/* Set your working directory as Stata folder in the Replication_folder */

local DIR ="C:\Users\...\EU Identity\Stata"
cap cd "`DIR'"

********************************************************************************
/* Install/update the following packagages if you have not before */

capture noisily net install rdrobust, from(https://sites.google.com/site/rdpackages/rdrobust/stata) replace all

capture noisily net install blindschemes, from(http://fmwww.bc.edu/RePEc/bocode/b) replace all
capture noisily net install blindschemes_fix, from(http://digital.cgdev.org/doc/stata/MO/Misc) replace all

capture noisily net install estout, from(http://fmwww.bc.edu/RePEc/bocode/e) replace all

capture noisily net install coefplot, from(http://fmwww.bc.edu/RePEc/bocode/c) replace all

********************************************************************************
/* Run the following program (write_mat) each time before replicating 

Source: https://github.com/alemartinello/write_mats/blob/master/myados/write_mats.ado 

*/
capture program drop write_mats
program define write_mats
	syntax namelist (max=3) using [, names(string) STARs(namelist min=2 max=2) PARentheses(string) ///
	NDecimals(integer 3) append(namelist max=1) appendnames(string) space(real 0.5)]
	
	* name beta and serr matrix as first and second matrix of namelist "stars"
	if "`stars'"!="" gettoken beta serr : stars
	* checks nr and nc
	local count = 1
	foreach mat in `namelist' `stars' {
		if `count'==1 {
			local nc = colsof(`mat')
			local nr = rowsof(`mat')
		}
		else{
			if `nc'!=colsof(`mat') | `nr'!=rowsof(`mat') {
				di as error "Matrix dimensions do not match"
				exit
			}
		}
	}
	if "`append'"!=""{
		if `nc'!=colsof(`append') {
			di as error "Matrix dimensions do not match"
			exit	
		}
	}
	
	if "`parentheses'"=="" local parentheses "() []"
	tokenize `parentheses'
	local np = wordcount("`parentheses'")
	forval i=1/`np' {
		local cp = `i'+1
		local paro`cp' = substr("``i''",1,1)
		local parc`cp' = substr("``i''",2,2) 
	}
	
	local nm = wordcount("`namelist'")
		
	file open table `using', write text replace
	forval i=1/`nr' {
		
		*label row
		if `"`names'"'!="" gettoken lab names: names
		else local lab `i'
		file write table "`lab'" _tab
		
		forval v=1/`nm' {
			* get name of matrix
			local vec=word("`namelist'",`v')
			forval j=1/`nc' {
				if "`stars'"!="" & "`vec'"=="`beta'" {
					local z = normal(abs((`beta'[`i',`j'])/(`serr'[`i',`j'])))
					if `z'>0.995 local st "$^{**}$ " 
					else if `z'>0.975 local st "$^{*}$  "
					else if `z'>0.95 local st "$^{+}$  "
					else local st "   " 
				}
				else local st "   "
				
				if `v'==1 local paro " "
				else if `v'==2 local paro "`paro2'"
				else if `v'==3 local paro "`paro3'"
				
				if `v'==1 local parc ""
				else if `v'==2 local parc "`parc2'"
				else if `v'==3 local parc "`parc3'"
				
				local towrite = string(`vec'[`i',`j'],"%9.`ndecimals'f")
				if (`vec'[`i',`j']) != . {
					file write table "&" "`paro'`towrite'`parc'""`st'"
				}
				else {
					file write table "&"
				}
			}
			if `v'==`nm' & `i'!=`nr' file write table " \\" _newline "[`space'em]" _newline
			else file write table " \\" _newline _tab
		}
		
	}
	if "`append'"!="" {
		file write table "\midrule" _newline
		local nr = rowsof(`append')
		forval i=1/`nr' {
			
			*label row
			if `"`appendnames'"'!="" gettoken lab appendnames: appendnames
			else local lab `i'
			file write table "`lab'" _tab
			forval j=1/`nc' {
				// To avoid reporting .000 for number of observations
				if `append'[`i',`j']>999 local revised_ndecimal 0
				else local revised_ndecimal `ndecimals'
				if `append'[`i',`j']!=. file write table "& " %12.`revised_ndecimal'f (`append'[`i',`j']) "     "
				else file write table "& "
			}
		file write table " \\" _newline
		}
	}
	
	
	file close table
	
end

********************************************************************************
set more off,perm
clear matrix
clear mata
set mat 5000

/*create folders "data processed" (where processed data are stored) and
"tables" (where tables are stored)*/
program define confirmdir, rclass
		local cwd `"`c(pwd)'"'
		quietly capture cd `"`1'"'
		local confirmdir=_rc 
		quietly cd `"`cwd'"'
		return local confirmdir `"`confirmdir'"'
	end 
		confirmdir `"processed data"'	  	/* does folder "processed data" exist? */
			if `r(confirmdir)'!=0  {  	/* folder does not yet exist */
				mkdir "processed data"  	/* makes the folder  */
							  } 
			  else {
				di "folder data processed already exists"
				}
		confirmdir `"tables"'		  /* does folder "tables" exist? */
			if `r(confirmdir)'!=0  {  /* folder does not yet exist */
				mkdir "tables"  /* makes the folder  */
							  } 
			  else {
				di "folder tables already exists"
				}
*		confirmdir `"ado"'		  /* does folder "ado" exist? */
*			if `r(confirmdir)'!=0  {  /* folder does not yet exist */
*				mkdir "ado"  /* makes the folder  */
*							  } 
*			  else {
*				di "folder ado already exists"
*				}
	program drop confirmdir
	
*********** Set Color Scheme for graphics by Daniel Bischof

set scheme plottig	

********************* Creation of Globals *******************************************

global coordinates point_x_meters point_y_meters
global segment close_north close_mid
global segment2 AL_seg1 AL_seg2 AL_seg3 AL_seg4 
global distances dist_b_ASLR_DEU dist_c_METZ dist_c_STRASBOURG dist_c_NANCY dist_mulhouse
global pretreatment road_length river_length LU_grazing_1860 LU_cropland_1860 popdens_1866 p1866 er_rug st_dev_elev er_elev sui_sfl sui_oni sui_wpo sui_whe sui_brl gare_1860 hie_1860

********************************************************************************
*******************  Table 2 Descriptive Table for Outcomes   ******************
********************************************************************************

use "processed data\letter_AlsaceLorraine.dta",clear

eststo: estpost summarize r92_yf r05_yf if treat_AL !=.

esttab using "..\Paper EU Identity\Tables\Table2_Descriptive_1.tex", cells("count(fmt(0) label(\textbf{Obs.})) mean(fmt(2) label(\textbf{Mean})) sd(fmt(2) label(\textbf{St. Dev.})) min(fmt(2) label(\textbf{Min.})) max(fmt(2) label(\textbf{Max.}))") nomtitles collabels(none) fragment nolines nogaps nonumbers booktabs noobs compress label replace varlabel(r92_yf "EU Support (1992)" r05_yf "EU Support (2005)")

estimates drop _all

use "processed data\reshaped_letter_AlsaceLorraine.dta",clear	

eststo: estpost summarize sum_EUvoteshare_neg sum_EUvoteshare_neg_noFN sum_weight_EUvoteshare_neg2_ if treat_AL !=.

esttab using "..\Paper EU Identity\Tables\Table2_Descriptive_2.tex", cells("count(fmt(0) label(\textbf{Obs.})) mean(fmt(2) label(\textbf{Mean})) sd(fmt(2) label(\textbf{St. Dev.})) min(fmt(2) label(\textbf{Min.})) max(fmt(2) label(\textbf{Max.}))") nomtitles collabels(none) fragment nolines nogaps nonumbers booktabs noobs compress label replace varlabel(sum_EUvoteshare_neg "Eurosceptic Parties (94-14)" sum_EUvoteshare_neg_noFN "w/o Front National (94-14)" sum_weight_EUvoteshare_neg2_ "Euroscepticism Index (94-14)" )

estimates drop _all

********************************************************************************
*******************  Figure 3 Cahiers de Doléances   ***************************
********************************************************************************

import excel "processed data\Cahiers France\cahiers1789.xlsx", sheet("data") clear	first
collapse (mean) meant= ThirdandUnited meante=ThirdEstate meanu=UnitedOrders (sd) sdt=ThirdandUnited sdte=ThirdEstate sdu=UnitedOrders (count) n=ThirdandUnited nte=ThirdEstate nu=UnitedOrders , by(Treated)

*replace Treated=2 if Treated==1
gen te=0
replace te = 6 if Treated==1 

gen  u=1.5
replace u = 7.5 if Treated==1 

gen t= 3
replace t=9 if Treated==1 


generate hite = meante + invttail(n-1,0.025)*(sdt / sqrt(nte))
generate lote = meante - invttail(n-1,0.025)*(sdt / sqrt(nte))


generate hiu = meante + invttail(n-1,0.025)*(sdt / sqrt(nu))
generate lou = meante - invttail(n-1,0.025)*(sdt / sqrt(nu))


gen meantu = 0 
replace meantu= 2.09375 if Treated==0
replace meantu= 2.083333333 if Treated==1 


twoway (bar meante te ) (bar meanu u, color(gs10) ) (bar meantu t,color(ply3))  (rcap hite lote te, lcolor("gray")) (rcap hiu lou u, lcolor("gray")) , ///
xscale(range(-1 8)) xlabel( 1.5 `""Control area" "(N=19)" "' 7.5 `""Treated area" "(N=10)" "', labsize(medlarge) labcolor(black) noticks) ///
legend( order( 1 "Third Estate" 2  "United Orders" 3 "Mean") size(medlarge))  yscale(range(0 3)) yla(0 1 2 3)  xtitle("") ytitle("Loyalty to nation",size(medlarge))

graph export "..\Paper EU Identity\Graphs\Fig3_Cahiers_de_Doleances.pdf", replace 

********************************************************************************
*********  Figure 4 Smoothness in Pre-Treatment Variables at the Border   ******
********************************************************************************

use "processed data\letter_AlsaceLorraine.dta",clear
 
gen cant_ID = ID_2*1000+ID_3

egen st_LU_grazing_1860 = std(LU_grazing_1860) if treat_AL != .
egen st_LU_cropland_1860 = std(LU_cropland_1860) if treat_AL != .
egen st_river_length = std(river_length) if treat_AL != .
egen st_road_length = std(road_length) if treat_AL != .
egen st_res_1860 = std(res_1860) if treat_AL != .
egen st_gare_1860 = std(gare_1860) if treat_AL != .
egen st_hie_1860 = std(hie_1860) if treat_AL != .

mat B=J(16,2,0)

local no = 1
quietly: rdrobust st_barley distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) vce(cluster cant_ID) h(10)
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix B[`no', 1] =  b`no'
matrix B[`no', 2] =  s`no'
local no = `no'+1
quietly: rdrobust st_wheat distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) vce(cluster cant_ID) h(10)
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix B[`no', 1] =  b`no'
matrix B[`no', 2] =  s`no'
local no = `no'+1
quietly: rdrobust st_potato distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) vce(cluster cant_ID)
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix B[`no', 1] =  b`no'
matrix B[`no', 2] =  s`no'
local no = `no'+1
quietly: rdrobust st_onion distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) vce(cluster cant_ID) h(10)
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix B[`no', 1] =  b`no'
matrix B[`no', 2] =  s`no'
local no = `no'+1
quietly: rdrobust st_sfl distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) vce(cluster cant_ID) h(10)
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix B[`no', 1] =  b`no'
matrix B[`no', 2] =  s`no'
local no = `no'+1
quietly: rdrobust st_elevation distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) vce(cluster cant_ID)
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix B[`no', 1] =  b`no'
matrix B[`no', 2] =  s`no'
local no = `no'+1
quietly: rdrobust st_st_dev_elev distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) vce(cluster cant_ID)
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix B[`no', 1] =  b`no'
matrix B[`no', 2] =  s`no'
local no = `no'+1
quietly: rdrobust st_ruggedness distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) vce(cluster cant_ID)
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix B[`no', 1] =  b`no'
matrix B[`no', 2] =  s`no'
local no = `no'+1
quietly: rdrobust st_river_length distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) vce(cluster cant_ID) 
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix B[`no', 1] =  b`no'
matrix B[`no', 2] =  s`no'
local no = `no'+1
rdrobust st_population distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) vce(cluster cant_ID) 
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix B[`no', 1] =  b`no'
matrix B[`no', 2] =  s`no'
local no = `no'+1
rdrobust st_popdensity distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) vce(cluster cant_ID)
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix B[`no', 1] =  b`no'
matrix B[`no', 2] =  s`no'
local no = `no'+1 
quietly: rdrobust st_LU_cropland_1860 distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) vce(cluster cant_ID) h(10)
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix B[`no', 1] =  b`no'
matrix B[`no', 2] =  s`no'
local no = `no'+1
quietly: rdrobust st_LU_grazing_1860 distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) vce(cluster cant_ID) h(10)
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix B[`no', 1] =  b`no'
matrix B[`no', 2] =  s`no'
local no = `no'+1
rdrobust st_road_length distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) vce(cluster cant_ID)
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix B[`no', 1] =  b`no'
matrix B[`no', 2] =  s`no'
local no = `no'+1
rdrobust st_gare_1860 distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) vce(cluster cant_ID)
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix B[`no', 1] =  b`no'
matrix B[`no', 2] =  s`no'
local no = `no'+1
rdrobust st_hie_1860 distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) vce(cluster cant_ID)
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix B[`no', 1] =  b`no'
matrix B[`no', 2] =  s`no'
local no = `no'+1
coefplot matrix(B[,1]), se(B[,2]) xline(0, lcolor(black)) /// 
coeflabels(r1 = "Suitability (Barley)" r2 = "Suitability (Wheat)" r3 = "Suitability (Potato)" r4 = "Suitability (Onion)" r5 = "Suitability (Sunflower)" r6 = "Elevation" r7 = "St. Dev. Elevation" r8 = "Ruggedness" r9 = "River Length" r10 = "Population" r11 = "Population Density" r12 = "Cropland" r13 = "Grazing Land" r14 = "Road Length" r15 = "Railway Station" r16 =  "Railway Quality") xtitle("Coefficient (standardized)" , ///
color(black) margin(medium)) levels(95)  mcolor(black) ciopts(lcolor(black)) msize(medium) graphregion(color(white)) xlabel(-1 "-1" -0.8 "-0.8" -0.6 "-0.6" -0.4 "-0.4" -0.2 "-0.2" 0 "0" 0.2 "0.2" 0.4 "0.4" 0.6 "0.6" 0.8 "0.8" 1 "1", nogrid)  headings(r1 = "{bf:Panel A: Geographic Variables}" r10 = "{bf:Panel B: Socio-Economic Variables}") 

graph export "..\Paper EU Identity\Graphs\Fig4_Smoothness_in_PreTreatment_Variables_at_the_Border.tif", replace width(3000) height(2000)
graph export "..\Paper EU Identity\Graphs\Fig4_Smoothness_in_PreTreatment_Variables_at_the_Border.pdf", replace

estimates drop _all

********************************************************************************
*********  Figure 5a) Average Agreement in EU Referendum 1972 in %   ***********
********************************************************************************

** changing graph scheme (attention to switch it back at the end of the graph creation)
set scheme s2color
use "processed data\collapsed_letter_AlsaceLorraine.dta",clear	

keep if treat_AL !=. 
	
collapse treat_AL, by(ID_2)
	
gen yes_72 = 75.1 if ID_2 == 57	
replace yes_72 = 67.5 if ID_2 == 54		
replace yes_72 = 71.0 if ID_2 == 55	
replace yes_72 = 72.6 if ID_2 == 88	
replace yes_72 = 84.6 if ID_2 == 67		
replace yes_72 = 82.5 if ID_2 == 68

label define treatment 0 "Control" 1 "Treatment"
label values treat_AL treatment
	
// add orange line in graph editor	
		
graph twoway bar yes_72  treat_AL if treat_AL == 0, bcolor(gs14) barwidth(.75) || bar yes_72 treat_AL if treat_AL == 1, bcolor(gs5) lcolor(gs14) ytitle("Share 'Yes' Referendum 1972 (in %)") graphregion(color(white)) xlabel(0  "Control" 1  "Treatment", noticks) xtitle("") barwidth(.75) legend(off) yscale(range(40(15)85)) ylabel(40 55 70 85) 	
set scheme plottig, permanently

graph export "..\Paper EU Identity\Graphs\Fig5a_Average_Agreement_in_EU_Referendum_1972.tif", replace width(3000) height(2000)
graph export "..\Paper EU Identity\Graphs\Fig5a_Average_Agreement_in_EU_Referendum_1972.pdf", replace

********************************************************************************
*****  Figure 5b) Agreement in EU Referenda, Average in 1992 & 2005 in %   *****
********************************************************************************

set scheme plottig

use "processed data\reshaped_letter_AlsaceLorraine.dta",clear
estimates drop _all

keep if year == 1992 | year == 2005

gen cant_ID = ID_2*1000+ID_3

rdrobust yes_share distance2 if treat_AL != ., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) vce(cluster cant_ID) 


twoway (lfitci  yes_share distance2 if distance2>= -12.530     & distance2 <= 0 & treat_AL !=., range(-12.3   -0.2) clcolor(black) clwidth(*1.2)) ///
 (scatter  yes_share distance2 if distance2>= -20  & distance2 <= 0 & treat_AL !=., msize(vtiny) mcolor(gs7) ) ///
 (lfitci  yes_share distance2 if distance2 >= 0 & distance2 <= 12.530     & treat_AL !=., range(0.2 12.3 ) clcolor(black) clwidth(*1.2)) ///
 (scatter  yes_share distance2 if distance2 >= 0 & distance2 <= 20    & treat_AL !=., msize(vtiny) mcolor(gs7)), ///
 legend(off) xscale(fex) graphregion(color(white)) xtitle("Distance to border", size(large) height(7)) ytitle("Vote Share 'Yes' (in %)", size(large)) xline(-12.530, lcolor(black) lpattern(dash)) xline(0, lcolor(orange) lpattern(dash)) xline(12.530, lcolor(black) lpattern(dash)) xlabel( -12.530 "-12.530 km" 0 "0 km" 12.530 "12.530 km" ,labsize(large)) ylabel(,labsize(large))

graph export "..\Paper EU Identity\Graphs\Fig5b_Agreement_in_EU_Referenda_Average_in_1992_2005.tif", replace
graph export "..\Paper EU Identity\Graphs\Fig5b_Agreement_in_EU_Referenda_Average_in_1992_2005.pdf", replace

********************************************************************************
*** Figure 5c) Average Vote Share Eurosceptic Parties in EU Parliamentary Elections 1994-2004 in % ***
********************************************************************************

use "processed data\reshaped_letter_AlsaceLorraine.dta",clear
estimates drop _all

keep if year == 1994 | year == 1999 | year == 2004

gen cant_ID = ID_2*1000+ID_3

rdrobust sum_EUvoteshare_neg distance2 if treat_AL != ., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) vce(cluster cant_ID) 

twoway (lfitci  sum_EUvoteshare_neg distance2 if distance2>= -14.369     & distance2 <= 0 & treat_AL !=., range(-14.2    -0.2) clcolor(black) clwidth(*1.2)) ///
 (scatter  sum_EUvoteshare_neg distance2 if distance2>= -30  & distance2 <= 0 & treat_AL !=., msize(vtiny) mcolor(gs7) ) ///
 (lfitci  sum_EUvoteshare_neg distance2 if distance2 >= 0 & distance2 <= 14.369     & treat_AL !=., range(0.2 14.2 ) clcolor(black) clwidth(*1.2)) ///
 (scatter  sum_EUvoteshare_neg distance2 if distance2 >= 0 & distance2 <= 30    & treat_AL !=., msize(vtiny) mcolor(gs7)), ///
 legend(off) xscale(fex) graphregion(color(white)) xtitle("Distance to border", size(large) height(7)) ytitle("Eurosceptic Vote Share (in %)", size(large)) xline(-14.369 , lcolor(black) lpattern(dash)) xline(0, lcolor(orange) lpattern(dash)) xline(14.369 , lcolor(black) lpattern(dash)) xlabel( -14.369  "-14.369 km" 0 "0 km" 14.369  "14.369 km" ,labsize(large)) ylabel(,labsize(large))

graph export "..\Paper EU Identity\Graphs\Fig5c_Average_Vote_Share_Eurosceptic_Parties.tif", replace
graph export "..\Paper EU Identity\Graphs\Fig5c_Average_Vote_Share_Eurosceptic_Parties.pdf", replace

********************************************************************************
******* Table 3 RD Results - EU Support and Euroscepticism (1992 - 2005) *******
********************************************************************************

estimates drop _all
use "processed data\letter_AlsaceLorraine.dta",clear

gen cant_ID = ID_2*1000+ID_3

reg r92_yf i.treat_AL##c.distance2 $distances $segment2 if treat_AL !=. & distance2 > -10 & distance2 < 10, cluster(cant_ID) r


eststo: rdrobust r92_yf distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) vce(cluster cant_ID) h(10) 
estadd local Obs = e(N_h_r) + e(N_h_l) 
eststo: rdrobust r92_yf distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) vce(cluster cant_ID) 
estadd local Obs = e(N_h_r) + e(N_h_l) 
eststo: rdrobust r05_yf distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) vce(cluster cant_ID) h(10) 
estadd local Obs = e(N_h_r) + e(N_h_l) 
eststo: rdrobust r05_yf distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2)  vce(cluster cant_ID) h(10) 
estadd local Obs = e(N_h_r) + e(N_h_l)  

use "processed data\reshaped_letter_AlsaceLorraine.dta",clear

keep if year == 1992 | year == 2005

gen cant_ID = ID_2*1000+ID_3

eststo: rdrobust yes_share distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) vce(cluster cant_ID) h(10) 
estadd local Obs = e(N_h_r) + e(N_h_l) 
eststo: rdrobust yes_share distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) vce(cluster cant_ID)
estadd local Obs = e(N_h_r) + e(N_h_l) 
		
esttab using "..\Paper EU Identity\Tables\Table3_PanelA.tex", fragment booktabs nostar replace cells(b(star fmt(3) nostar) se(par(( )) abs fmt(3)) p(par({[ ]}) abs fmt(3)))  ///
				mlabel(none) style(fixed) collabels(none) nolines nogaps nonumbers varlabel(RD_Estimate "Treatment vs. Control") ///
				stats(h_r Obs, fmt(3 0) label("Bandwidth (km)" "Observations")) noabbr 

use "processed data\letter_AlsaceLorraine.dta",clear
estimates drop _all

gen ymean = r92_yf

eststo: estpost sum ymean if treat_AL ==0 & distance2 > -10 & distance2 < 10, meanonly
eststo: estpost sum ymean if treat_AL ==0 & distance2 > -13.419  & distance2 < 13.419 , meanonly

replace ymean = r05_yf

eststo: estpost sum ymean if treat_AL ==0 & distance2 > -10 & distance2 < 10, meanonly
eststo: estpost sum ymean if treat_AL ==0 & distance2 > -10   & distance2 < 10  , meanonly

use "processed data\reshaped_letter_AlsaceLorraine.dta",clear
keep if year == 1992 | year == 2005

gen ymean = yes_share

eststo: estpost sum ymean if treat_AL ==0 & distance2 > -10 & distance2 < 10, meanonly
eststo: estpost sum ymean if treat_AL ==0 & distance2 > -12.530  & distance2 < 12.530 , meanonly

esttab using "..\Paper EU Identity\Tables\Table3_PanelA_Mean_of_Outcome.tex", cells("mean(fmt(2))") nomtitles collabels(none) fragment postfoot(\hline) nolines nogaps nonumbers booktabs noobs compress label replace varlabel(ymean "Mean of Outcome (Control)") 

estimates drop _all
drop ymean


estimates drop _all

use "processed data\reshaped_letter_AlsaceLorraine.dta", clear
estimates drop _all
drop if insee_code == 1

keep if year == 1994 | year == 1999 | year == 2004

gen cant_ID = ID_2*1000+ID_3

eststo: rdrobust sum_EUvoteshare_neg distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) vce(cluster cant_ID) h(10)
estadd local Obs = e(N_h_r) + e(N_h_l) 
eststo: rdrobust sum_EUvoteshare_neg distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) vce(cluster cant_ID)
estadd local Obs = e(N_h_r) + e(N_h_l)
eststo: rdrobust sum_EUvoteshare_neg_noFN distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) vce(cluster cant_ID) h(10)
estadd local Obs = e(N_h_r) + e(N_h_l) 
eststo: rdrobust sum_EUvoteshare_neg_noFN distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) vce(cluster cant_ID)
estadd local Obs = e(N_h_r) + e(N_h_l)
eststo: rdrobust sum_weight_EUvoteshare_neg2_ distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) vce(cluster cant_ID) h(10)
estadd local Obs = e(N_h_r) + e(N_h_l) 
eststo: rdrobust sum_weight_EUvoteshare_neg2_ distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) vce(cluster cant_ID)
estadd local Obs = e(N_h_r) + e(N_h_l)  

esttab using "..\Paper EU Identity\Tables\Table3_PanelB.tex", fragment booktabs nostar replace cells(b(star fmt(3) nostar) se(par(( )) abs fmt(3)) p(par({[ ]}) abs fmt(3)))  ///
				mlabel(none) style(fixed) collabels(none) nolines nogaps nonumbers varlabel(RD_Estimate "Treatment vs. Control") ///
				stats(h_r Obs, fmt(3 0) label("Bandwidth (km)" "Observations")) noabbr 
						
estimates drop _all

gen ymean = sum_EUvoteshare_neg

eststo: estpost sum ymean if treat_AL ==0 & distance2 > -10 & distance2 < 10, meanonly
eststo: estpost sum ymean if treat_AL ==0 & distance2 > - 14.369    & distance2 <  14.369   , meanonly


replace ymean = sum_EUvoteshare_neg_noFN 

eststo: estpost sum ymean if treat_AL ==0 & distance2 > -10 & distance2 < 10, meanonly
eststo: estpost sum ymean if treat_AL ==0 & distance2 > -17.819     & distance2 < 17.819  , meanonly

replace ymean = sum_weight_EUvoteshare_neg2_

eststo: estpost sum ymean if treat_AL ==0 & distance2 > -10 & distance2 < 10, meanonly
eststo: estpost sum ymean if treat_AL ==0 & distance2 > -16.675      & distance2 < 16.675 , meanonly

esttab using "..\Paper EU Identity\Tables\Table3_PanelB_Mean_of_Outcome.tex", cells("mean(fmt(2))") nomtitles collabels(none) fragment postfoot(\hline) nolines nogaps nonumbers booktabs noobs compress label replace varlabel(ymean "Mean of Outcome (Control)") 

estimates drop _all
drop ymean

********************************************************************************
*** Figure 6 Robustness - Modified Border Excluding Overlaps with Linguistic Border ***
********************************************************************************

use "processed data\reshaped_letter_AlsaceLorraine.dta", clear
estimates drop _all
drop if insee_code == 1

keep if year == 1992 | year == 2005 | year == 1994 | year == 1999 | year == 2004

gen cant_ID = ID_2*1000+ID_3

gen distance_robust_border2 = distance_robust_border/1000
replace distance_robust_border2 = distance_robust_border2*-1 if row_dum2 == 0

gen is_oldmoselle = FE_moselle
replace is_oldmoselle = 0 if FE_meurthe ==1
replace is_oldmoselle = . if FE_moselle != 1 & FE_meurthe !=1

gen distance_old_meu_mos = dist_old_border
replace distance_old_meu_mos = dist_old_border * -1 if is_oldmoselle == 0
replace distance_old_meu_mos = . if is_oldmoselle == .

gen distance_old_meu_mos2 = distance_old_meu_mos/1000

gen is_borderingAL = 0 if treat_AL == 0
replace is_borderingAL = 1 if ID_2 == 8 | ID_2 == 51 | ID_2 == 52 | ID_2 == 70 

gen distance_france = dist_AL_restFRA
replace distance_france = distance_france * -1 if is_borderingAL == 1
replace distance_france = . if is_borderingAL == .

gen distance_france2 = distance_france/1000


gen dist_limited = distance_limited
replace dist_limited = distance_limited*-1 if treat_AL == 0
gen dist_limited2 = dist_limited/1000

mat C=J(4,2,0)

local no = 1
rdrobust yes_share distance2 if treat_AL !=. , rho(1) kernel(uni) masspoints(off) covs($distances) vce(cluster cant_ID)
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix C[`no', 1] =  b`no'
matrix C[`no', 2] =  s`no'
local no = `no'+1
rdrobust yes_share dist_limited2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances) vce(cluster cant_ID)
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix C[`no', 1] =  b`no'
matrix C[`no', 2] =  s`no'
local no = `no'+1
rdrobust sum_EUvoteshare_neg distance2 if treat_AL !=. , rho(1) kernel(uni) masspoints(off) covs($distances) vce(cluster cant_ID) 
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix C[`no', 1] =  b`no'
matrix C[`no', 2] =  s`no'
local no = `no'+1
rdrobust sum_EUvoteshare_neg dist_limited2 if treat_AL !=. , rho(1) kernel(uni) masspoints(off) covs($distances) vce(cluster cant_ID)
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix C[`no', 1] =  b`no'
matrix C[`no', 2] =  s`no'
local no = `no'+1
coefplot matrix(C[,1]), se(C[,2]) xline(0, lcolor(black)) msize(medium) xlabel(-2 0 2 4 6) xscale(range(-4 8))  /// 
coeflabels(r1 = "Baseline" r2 = "Modified" r3 = "Baseline"  r4 = "Modified", labsize(medium)) levels(90) ciopts(lcolor(black) lstyle(p15)) graphregion(color(white)) headings(r1 = "{bf:EU Support}" r3 = "{bf:Euroscepticism}", labsize(medlarge)) xlabel( -2 0 2 4 6, nogrid)

graph export "..\Paper EU Identity\Graphs\Fig6_Robustness.tif", replace width(3000) height(2000)
graph export "..\Paper EU Identity\Graphs\Fig6_Robustness.pdf", replace

estimates drop _all

************************************************************************************************
*** Figure 7 and C.1 Mechanisms: Population Changes, Socioeconomic Factors, and Public Goods ***
************************************************************************************************

use "processed data\letter_AlsaceLorraine.dta",clear

gen cant_ID = ID_2*1000+ID_3
gen pop_density99=pop_total99 /area
gen pop_density90=pop_total90 /area

gen change_46_36 = Population_1946 - Population_1936
gen change_46_26 = Population_1946 - Population_1926
gen change_46_16 =  Population_1946 - Population_1916
gen change_1946_1866 = Population_1946 - p1866

egen st_share15_BAC99 = std(share15_BAC99) if treat_AL !=.
egen st_mean_age06 = std(mean_age06) if treat_AL !=.
egen st_share15_workers06 = std(share15_workers06) if treat_AL !=.
egen st_median_income08= std(median_income08) if treat_AL !=.
egen st_median_income01= std(median_income01) if treat_AL !=.
egen st_healthcare_pc = std(healthcare_pc) if treat_AL !=.
egen st_high_school_pc = std(high_school_pc) if treat_AL !=.
egen st_vocational_school_pc = std(vocational_school_pc) if treat_AL !=.
egen st_post_office_pc = std(post_office_pc) if treat_AL !=.
egen st_healthcare98 = std(healthcare98) if treat_AL !=.
egen st_high_school98 = std(high_school98) if treat_AL !=.
egen st_vocational_school98 = std(vocational_school98) if treat_AL !=.
egen st_post_office98 = std(post_office98) if treat_AL !=.
egen st_change_1946_1866 = std(change_1946_1866) if treat_AL !=.
egen st_change_46_16 = std(change_46_16) if treat_AL !=.
egen st_change_46_26 = std(change_46_26) if treat_AL !=.
egen st_change_46_36 = std(change_46_36) if treat_AL !=.

egen st_mean_age_99  = std(mean_age_99) if treat_AL !=.
egen st_mean_age_90  = std(mean_age_90) if treat_AL !=.
egen st_pop_density99  = std(pop_density99) if treat_AL !=.
egen st_pop_density90  = std(pop_density90) if treat_AL !=.
egen st_urban_rural99  = std(urban_rural99) if treat_AL !=.
egen st_out_wedlock90  = std(out_wedlock90) if treat_AL !=.
egen st_out_wedlock99  = std(out_wedlock99) if treat_AL !=.
egen st_single_parents90  = std(single_parents90) if treat_AL !=.
egen st_single_parents99  = std(single_parents99) if treat_AL !=.
egen st_share_bluecollar99  = std(share_bluecollar99) if treat_AL !=.
egen st_foreigner_share2006 = std(foreigner_share2006) if treat_AL !=.

mat B=J(18,2,0)


*population*

local no = 1
quietly: rdrobust st_change_1946_1866 distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) vce(cluster cant_ID)
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix B[`no', 1] =  b`no'
matrix B[`no', 2] =  s`no'
local no = `no'+1
quietly: rdrobust st_change_46_16 distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) vce(cluster cant_ID) 
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix B[`no', 1] =  b`no'
matrix B[`no', 2] =  s`no'
local no = `no'+1
quietly: rdrobust st_change_46_26 distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) vce(cluster cant_ID) 
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix B[`no', 1] =  b`no'
matrix B[`no', 2] =  s`no'
local no = `no'+1 
quietly: rdrobust st_change_46_36 distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) vce(cluster cant_ID)
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix B[`no', 1] =  b`no'
matrix B[`no', 2] =  s`no'

*socioeconomic*

local no = `no'+1
quietly: rdrobust st_urban_rural99 distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) vce(cluster cant_ID)
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix B[`no', 1] =  b`no'
matrix B[`no', 2] =  s`no'
local no = `no'+1
quietly: rdrobust st_pop_density90 distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) vce(cluster cant_ID) 
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix B[`no', 1] =  b`no'
matrix B[`no', 2] =  s`no'
local no = `no'+1
quietly: rdrobust st_share15_BAC99 distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) vce(cluster cant_ID)
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix B[`no', 1] =  b`no'
matrix B[`no', 2] =  s`no'
local no = `no'+1
quietly: rdrobust st_mean_age_90 distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) vce(cluster cant_ID)
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix B[`no', 1] =  b`no'
matrix B[`no', 2] =  s`no'
local no = `no'+1
quietly: rdrobust st_foreigner_share2006 distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off)  covs($distances $segment2) vce(cluster cant_ID)
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix B[`no', 1] =  b`no'
matrix B[`no', 2] =  s`no'
local no = `no'+1
quietly: rdrobust st_share_bluecollar99 distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) vce(cluster cant_ID)
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix B[`no', 1] =  b`no'
matrix B[`no', 2] =  s`no'
local no = `no'+1
quietly: rdrobust st_median_income01 distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) vce(cluster cant_ID) 
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix B[`no', 1] =  b`no'
matrix B[`no', 2] =  s`no'

*publicgood*

local no = `no'+1
quietly: rdrobust st_healthcare98 distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) vce(cluster cant_ID) 
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix B[`no', 1] =  b`no'
matrix B[`no', 2] =  s`no'
local no = `no'+1
quietly: rdrobust st_high_school98 distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) vce(cluster cant_ID)
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix B[`no', 1] =  b`no'
matrix B[`no', 2] =  s`no'
local no = `no'+1
quietly: rdrobust st_vocational_school98 distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) vce(cluster cant_ID)
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix B[`no', 1] =  b`no'
matrix B[`no', 2] =  s`no'
local no = `no'+1
quietly: rdrobust st_post_office98 distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) vce(cluster cant_ID)
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix B[`no', 1] =  b`no'
matrix B[`no', 2] =  s`no'
local no = `no'+1
use "processed data\oip_attachment.dta", clear
quietly: reg st_attachement_europe is_aslr age gender employmentstatus diplome if treat_AL!=., r
scalar b`no' = _b[is_aslr]
scalar s`no' = _se[is_aslr]
matrix B[`no', 1] =  b`no'
matrix B[`no', 2] =  s`no'
local no = `no'+1
use "processed data\oip_euroCitizen.dta", clear
quietly: reg st_Euro_citizen is_aslr age gender employmentstatus diplome if treat_AL!=., r
scalar b`no' = _b[is_aslr]
scalar s`no' = _se[is_aslr]
matrix B[`no', 1] =  b`no'
matrix B[`no', 2] =  s`no'
local no = `no'+1
use "processed data\oip_EUR_pride.dta", clear

quietly: reg st_EUR_pride is_aslr age gender employmentstatus diplome if treat_AL!=., r
scalar b`no' = _b[is_aslr]
scalar s`no' = _se[is_aslr]
matrix B[`no', 1] =  b`no'
matrix B[`no', 2] =  s`no'
coefplot matrix(B[,1]), se(B[,2]) xline(0, lcolor(black)) /// 
coeflabels(r1 = "1866-1946" r2 = "1916-1946" r3 = "1926-1946" r4 = "1936-1946" r5="Urban municipality (1999)" r6="Population density (1990)" r7 = "Education (1999)" r8 = "Age (1990)" r9 = "Foreign residents (2006)" r10 = "Employment (1999)" r11 = "Income (2001)"  r12 = "Health Care (1998)" r13 = "High School (1998)" r14 = "Vocational School (1998)" r15 = "Post Office (1998)" r16="European Identity" r17="European Citizen" r18="European Pride") xtitle("Coefficient (standardized)" , ///
color(black) margin(medium)) levels(95) ciopts(lcolor(black) lstyle(p15)) msize(medium)  graphregion(color(white)) xlabel(-1 -0.8 -0.6 -0.4  -0.2  0  0.2  0.4 0.6 0.8 1, nogrid) headings(r5 = "{bf:Panel B: Socio-Economic Variables}" r1 = "{bf:Panel A: Population Change}" r12 = "{bf:Panel C: Public Goods}" r16 = "{bf:Panel D: European identity measures}")  

graph export "..\Paper EU Identity\Graphs\Fig7_Mechanisms.tif", replace width(3000) height(2000)
graph export "..\Paper EU Identity\Graphs\Fig7_Mechanisms.pdf", replace 

estimates drop _all

***************************************************************************************
*** Table 4 Nested Identities: EU, National, and Regional (Alsace & Lorraine) Level ***
***************************************************************************************

use "processed data\oip_attachment.dta", clear

eststo: reg st_attachement_region is_aslr age gender employmentstatus diplome if treat_AL!=., r
eststo: reg st_attachement_france is_aslr age gender employmentstatus diplome if treat_AL!=., r
eststo: reg st_attachement_europe is_aslr age gender employmentstatus diplome if treat_AL!=., r

esttab using "..\Paper EU Identity\Tables\Table4_PanelA.tex", fragment booktabs nostar replace cells(b(star fmt(3) nostar) se(par(( )) abs fmt(3)) p(par({[ ]}) abs fmt(3))) drop(_cons age gender employmentstatus diplome) ///
				mlabel(none) style(fixed) collabels(none) nolines nogaps nonumbers postfoot(\hline) varlabel(is_aslr "Treatment vs. Control")  /*prehead("")*/ ///
				stats( N, fmt( 0) label( "Observations")) noabbr 
			
estimates drop _all

use "processed data\oip_dev_planning.dta", clear
estimates drop _all
eststo: reg st_Reg_dev_plan is_aslr age gender employmentstatus diplome if treat_AL != ., r
eststo: reg st_Nat_dev_plan is_aslr age gender employmentstatus diplome if treat_AL != ., r
eststo: reg st_EU_dev_plan is_aslr age gender employmentstatus diplome if treat_AL != ., r

esttab using "..\Paper EU Identity\Tables\Table4_PanelB.tex", fragment booktabs nostar replace cells(b(star fmt(3) nostar) se(par(( )) abs fmt(3)) p(par({[ ]}) abs fmt(3))) drop(_cons age gender employmentstatus diplome) ///
				mlabel(none) style(fixed) collabels(none) nolines nogaps nonumbers postfoot(\hline) varlabel(is_aslr "Treatment vs. Control")  /*prehead("")*/ ///
				stats( N, fmt( 0) label(  "Observations")) noabbr 

estimates drop _all

* Relative *

eststo: reg st_Reg_Nat_dev_plan is_aslr age gender employmentstatus diplome if treat_AL != ., r
eststo: reg st_Nat_EU_dev_plan is_aslr age gender employmentstatus diplome if treat_AL != ., r
eststo: reg st_EU_Reg_dev_plan is_aslr age gender employmentstatus diplome if treat_AL != ., r

esttab using "..\Paper EU Identity\Tables\Table4_PanelC.tex", fragment booktabs nostar replace cells(b(star fmt(3) nostar) se(par(( )) abs fmt(3)) p(par({[ ]}) abs fmt(3))) drop(_cons age gender employmentstatus diplome) ///
				mlabel(none) style(fixed) collabels(none) nolines nogaps nonumbers postfoot(\hline) varlabel(is_aslr "Treatment vs. Control")  /*prehead("")*/ ///
				stats( N, fmt( 0) label(  "Observations")) noabbr 
				
estimates drop _all

********************************************************************************
**************  Figure 8d) Coefficient Plots at Placebo Borders  ***************
********************************************************************************

use "processed data\reshaped_letter_AlsaceLorraine.dta", clear
estimates drop _all
drop if insee_code == 1

keep if year == 1992 | year == 2005 | year == 1994 | year == 1999 | year == 2004

gen cant_ID = ID_2*1000+ID_3

gen distance_robust_border2 = distance_robust_border/1000
replace distance_robust_border2 = distance_robust_border2*-1 if row_dum2 == 0

gen is_oldmoselle = FE_moselle
replace is_oldmoselle = 0 if FE_meurthe ==1
replace is_oldmoselle = . if FE_moselle != 1 & FE_meurthe !=1

gen distance_old_meu_mos = dist_old_border
replace distance_old_meu_mos = dist_old_border * -1 if is_oldmoselle == 0
replace distance_old_meu_mos = . if is_oldmoselle == .

gen distance_old_meu_mos2 = distance_old_meu_mos/1000

gen is_borderingAL = 0 if treat_AL == 0
replace is_borderingAL = 1 if ID_2 == 8 | ID_2 == 51 | ID_2 == 52 | ID_2 == 70 

gen distance_france = dist_AL_restFRA
replace distance_france = distance_france * -1 if is_borderingAL == 1
replace distance_france = . if is_borderingAL == .

gen distance_france2 = distance_france/1000


gen dist_limited = distance_limited
replace dist_limited = distance_limited*-1 if treat_AL == 0
gen dist_limited2 = dist_limited/1000

mat B=J(6,2,0)

local no = 1
rdrobust yes_share distance_robust_border2 if treat_AL ==. & row_dum2 !=., rho(1) kernel(uni) masspoints(off) covs($distances) vce(cluster cant_ID)  
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix B[`no', 1] =  b`no'
matrix B[`no', 2] =  s`no'
local no = `no'+1
rdrobust sum_EUvoteshare_neg distance_robust_border2 if treat_AL ==. & row_dum2 !=., rho(1) kernel(uni) masspoints(off) covs($distances) vce(cluster cant_ID) 
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix B[`no', 1] =  b`no'
matrix B[`no', 2] =  s`no'
local no = `no'+1
rdrobust yes_share distance_old_meu_mos2  if is_oldmoselle !=., rho(1) kernel(uni) masspoints(off) covs($distances) vce(cluster cant_ID)  h(10)
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix B[`no', 1] =  b`no'
matrix B[`no', 2] =  s`no'
local no = `no'+1
rdrobust sum_EUvoteshare_neg distance_old_meu_mos2 if is_oldmoselle !=., rho(1) kernel(uni) masspoints(off) covs($distances) vce(cluster cant_ID) h(10)
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix B[`no', 1] =  b`no'
matrix B[`no', 2] =  s`no'
local no = `no'+1
rdrobust yes_share distance_france2 if is_borderingAL !=., rho(1) kernel(uni) masspoints(off) covs($distances) vce(cluster cant_ID) 
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix B[`no', 1] =  b`no'
matrix B[`no', 2] =  s`no'
local no = `no'+1
rdrobust sum_EUvoteshare_neg distance_france2 if is_borderingAL !=., rho(1) kernel(uni) masspoints(off) covs($distances) vce(cluster cant_ID) 
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix B[`no', 1] =  b`no'
matrix B[`no', 2] =  s`no'
local no = `no'+1
coefplot matrix(B[,1]), se(B[,2]) xline(0, lcolor(black)) msize(medium)  coeflabels(r1 = "EU Support" r2 = "Euroscepticism" r3= "EU Support" r4 = "Euroscepticism" r5= "EU Support" r6 = "Euroscepticism", labsize(medium)) levels(95) ciopts(lcolor(black)) graphregion(color(white)) xlabel(-6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6, nogrid) ///
headings(r1 = "{bf:Placebo Border (a)}" r3 = "{bf:Placebo Border (b)}" r5 = "{bf:Placebo Border (c)}", labsize(medlarge)) 

graph export "..\Paper EU Identity\Graphs\Fig8d_Placebo_Borders.tif", replace width(3000) height(2000)
graph export "..\Paper EU Identity\Graphs\Fig8d_Placebo_Borders.pdf", replace

estimates drop _all

********************************************************************************
*****************************   APPENDIX  **************************************
********************************************************************************

********************************************************************************
********************   Table A.1 Descriptive Table 1  **************************
********************************************************************************

use "processed data\letter_AlsaceLorraine.dta",clear

gen change_46_36 = Population_1946 - Population_1936
gen change_46_26 = Population_1946 - Population_1926
gen change_46_16 =  Population_1946 - Population_1916
gen change_1946_1866 = Population_1946 - p1866


replace dist_b_ASLR_DEU = dist_b_ASLR_DEU/1000
replace dist_c_METZ = dist_c_METZ/1000
replace dist_c_STRASBOURG = dist_c_STRASBOURG/1000
replace dist_c_NANCY  = dist_c_NANCY/1000
replace dist_mulhouse  = dist_mulhouse/1000
replace river_length  = river_length/1000
replace road_length = road_length/1000
replace dist_b_ASLR_FRA = dist_b_ASLR_FRA/1000

replace sum_weight_EUvoteshare_neg2_2004 = sum_weight_EUvoteshare_neg2_2004*100

estimates drop _all


eststo: estpost summarize is_aslr dist_b_ASLR_FRA if treat_AL !=.
esttab using "..\Paper EU Identity\Tables\Desc1.tex", cells("count(fmt(0) label(\textbf{Obs.})) mean(fmt(2) label(\textbf{Mean})) sd(fmt(2) label(\textbf{St. Dev.})) min(fmt(2) label(\textbf{Min.})) max(fmt(2) label(\textbf{Max.}))") nomtitles collabels(none) fragment nolines nogaps nonumbers booktabs noobs compress label replace varlabel(is_aslr "Treatment (Dummy)" dist_b_ASLR_FRA "Distance to Border (in km)" r92_yf "Vote Share 'Yes' 1992" r05_yf "Vote Share 'Yes' 2005" sum_EUvoteshare_neg1994 "Eurosceptic Parties 1994" sum_EUvoteshare_neg_noFN1994 "w/o Front National 1994" sum_weight_EUvoteshare_neg2_1994 "Euroscepticism Index 1994" sum_EUvoteshare_neg1999 "Eurosceptic Parties 1999" sum_EUvoteshare_neg_noFN1999 "w/o Front National 1999" sum_weight_EUvoteshare_neg2_1999 "Euroscepticism Index 1999" sum_EUvoteshare_neg2004 "Eurosceptic Parties 2004" sum_EUvoteshare_neg_noFN2004 "w/o Front National 2004" sum_weight_EUvoteshare_neg2_2004 "Euroscepticism Index 2004" ) 
estimates drop _all

eststo: estpost summarize r92_yf r05_yf sum_EUvoteshare_neg1994 sum_EUvoteshare_neg1999 sum_EUvoteshare_neg2004 sum_EUvoteshare_neg_noFN1994 sum_EUvoteshare_neg_noFN1999 sum_EUvoteshare_neg_noFN2004 sum_weight_EUvoteshare_neg2_1994 sum_weight_EUvoteshare_neg2_1999 sum_weight_EUvoteshare_neg2_2004   if treat_AL !=.
esttab using "..\Paper EU Identity\Tables\Desc2.tex", cells("count(fmt(0) label(\textbf{Obs.})) mean(fmt(2) label(\textbf{Mean})) sd(fmt(2) label(\textbf{St. Dev.})) min(fmt(2) label(\textbf{Min.})) max(fmt(2) label(\textbf{Max.}))") nomtitles collabels(none) fragment nolines nogaps nonumbers booktabs noobs compress label replace varlabel(is_aslr "Treatment (Dummy)" distance2 "Distance to Border (in km)" r92_yf "Vote Share 'Yes' 1992" r05_yf "Vote Share 'Yes' 2005" sum_EUvoteshare_neg1994 "Eurosceptic Parties 1994" sum_EUvoteshare_neg_noFN1994 "w/o Front National 1994" sum_weight_EUvoteshare_neg2_1994 "Euroscepticism Index 1994" sum_EUvoteshare_neg1999 "Eurosceptic Parties 1999" sum_EUvoteshare_neg_noFN1999 "w/o Front National 1999" sum_weight_EUvoteshare_neg2_1999 "Euroscepticism Index 1999" sum_EUvoteshare_neg2004 "Eurosceptic Parties 2004" sum_EUvoteshare_neg_noFN2004 "w/o Front National 2004" sum_weight_EUvoteshare_neg2_2004 "Euroscepticism Index 2004" ) 
estimates drop _all

eststo: estpost summarize dist_b_ASLR_DEU dist_c_METZ dist_c_STRASBOURG dist_c_NANCY dist_mulhouse AL_seg1 AL_seg2 AL_seg3 AL_seg4 AL_seg5 if treat_AL !=.
esttab using "..\Paper EU Identity\Tables\Desc3.tex", cells("count(fmt(0) label(\textbf{Obs.})) mean(fmt(2) label(\textbf{Mean})) sd(fmt(2) label(\textbf{St. Dev.})) min(fmt(2) label(\textbf{Min.})) max(fmt(2) label(\textbf{Max.}))")  nomtitles collabels(none) fragment nolines nogaps nonumbers booktabs noobs compress label replace varlabel( dist_b_ASLR_DEU "Distance to German Border (in km)" dist_c_METZ "Distance to Metz (in km)" dist_c_STRASBOURG "Distance to Strasbourg (in km)" dist_c_NANCY "Distance to Nancy (in km)" dist_mulhouse "Distance to Mulhouse (in km)" er_elev "Elevation" er_rug "Ruggedness" st_dev_elev "St. Dev. Elevation" river_length "River Length (in km)" road_length "Road Length (in km)" LU_cropland_1860 "Cropland" LU_grazing_1860 "Grazing Land" gare_1860 "Railway Station" hie_1860 "Railway Quality" popdens_1866 "Population Density 1866" point_x_meters "Point X-Coordinate (in m)" point_y_meters "Point Y-Coordinate (in m)" AL_seg1 "Treatment Border Segment 1 (Dummy)" AL_seg2 "Treatment Border Segment 2 (Dummy)" AL_seg3 "Treatment Border Segment 3 (Dummy)" AL_seg4 "Treatment Border Segment 4 (Dummy)" AL_seg5 "Treatment Border Segment 5 (Dummy)" )
estimates drop _all

********************************************************************************
********************   Table A.2 Descriptive Table 2  **************************
********************************************************************************

eststo: estpost summarize er_elev er_rug st_dev_elev river_length road_length gare_1860 hie_1860 LU_cropland_1860 LU_grazing_1860 popdens_1866 if treat_AL !=.
esttab using "..\Paper EU Identity\Tables\Desc4.tex", cells("count(fmt(0) label(\textbf{Obs.})) mean(fmt(2) label(\textbf{Mean})) sd(fmt(2) label(\textbf{St. Dev.})) min(fmt(2) label(\textbf{Min.})) max(fmt(2) label(\textbf{Max.}))")  nomtitles collabels(none) fragment nolines nogaps nonumbers booktabs noobs compress label replace varlabel( dist_b_ASLR_DEU "Distance to German Border (in km)" dist_c_METZ "Distance to Metz (in km)" dist_c_STRASBOURG "Distance to Strasbourg (in km)" dist_c_NANCY "Distance to Nancy (in km)" dist_mulhouse "Distance to Mulhouse (in km)" er_elev "Elevation" er_rug "Ruggedness" st_dev_elev "St. Dev. Elevation" river_length "River Length (in km)" road_length "Road Length (in km)" LU_cropland_1860 "Cropland" LU_grazing_1860 "Grazing Land" gare_1860 "Railway Station" hie_1860 "Railway Quality" popdens_1866 "Population Density 1866")
estimates drop _all

eststo: estpost summarize p1866 sui_brl sui_mze sui_oni sui_whe sui_wpo sui_sfl if treat_AL !=.
esttab using "..\Paper EU Identity\Tables\Desc5.tex", cells("count(fmt(0) label(\textbf{Obs.})) mean(fmt(0) label(\textbf{Mean})) sd(fmt(0) label(\textbf{St. Dev.})) min(fmt(0) label(\textbf{Min.})) max(fmt(0) label(\textbf{Max.}))") nomtitles collabels(none) fragment nolines nogaps nonumbers booktabs noobs compress label replace varlabel(sui_brl "Suitability (Barley)" sui_whe "Suitability (Wheat)" sui_wpo "Suitability (Potato)" sui_mze "Suitability (Maize)" sui_oni "Suitability (Onion)" sui_sfl "Suitability (Sunflower)" er_elev "Elevation"  p1866 "Population 1866" change_1946_1866 "Change Population 1866-1946" change_46_16 "Change Population 1916-1946" change_46_26 "Change Population 1926-1946" change_46_36 "Change Population 1936-1946" ) 
estimates drop _all

eststo: estpost summarize change_1946_1866  change_46_16 change_46_26 change_46_36  if treat_AL !=.
esttab using "..\Paper EU Identity\Tables\Desc6.tex", cells("count(fmt(0) label(\textbf{Obs.})) mean(fmt(0) label(\textbf{Mean})) sd(fmt(0) label(\textbf{St. Dev.})) min(fmt(0) label(\textbf{Min.})) max(fmt(0) label(\textbf{Max.}))") nomtitles collabels(none) fragment nolines nogaps nonumbers booktabs noobs compress label replace varlabel(sui_brl "Suitability (Barley)" sui_whe "Suitability (Wheat)" sui_wpo "Suitability (Potato)" sui_mze "Suitability (Maize)" sui_oni "Suitability (Onion)" sui_sfl "Suitability (Sunflower)" er_elev "Elevation"  p1866 "Population 1866" change_1946_1866 "Change Population 1866-1946" change_46_16 "Change Population 1916-1946" change_46_26 "Change Population 1926-1946" change_46_36 "Change Population 1936-1946" ) 
estimates drop _all

eststo: estpost summarize Turnout1992 Turnout2005 mean_age06 median_income08 share15_BAC99 share15_workers06 healthcare_pc high_school_pc vocational_school_pc post_office_ if treat_AL !=.
esttab using "..\Paper EU Identity\Tables\Desc7.tex", cells("count(fmt(0) label(\textbf{Obs.})) mean(fmt(2) label(\textbf{Mean})) sd(fmt(2) label(\textbf{St. Dev.})) min(fmt(2) label(\textbf{Min.})) max(fmt(2) label(\textbf{Max.}))") nomtitles collabels(none) fragment nolines nogaps nonumbers booktabs noobs compress label replace varlabel(Turnout1992 "Turnout 1992" Turnout2005 "Turnout 2005" mean_age06 "Age" median_income08 "Income" share15_BAC99 "Education" share15_workers06 "Employment" healthcare_pc "Health Care" high_school_pc "High School" vocational_school_pc "Vocational School" post_office_pc "Post Office") 
estimates drop _all	


********************************************************************************
*********   Figure C.2 Mechanisms: Extended Panel B and Panel C  ***************
********************************************************************************

use "processed data\letter_AlsaceLorraine.dta",clear

gen cant_ID = ID_2*1000+ID_3
gen pop_density99=pop_total99 /area
gen pop_density90=pop_total90 /area

egen st_mean_age_99  = std(mean_age_99) if treat_AL !=.
egen st_mean_age_90  = std(mean_age_90) if treat_AL !=.
egen st_median_age_99  = std(median_age_99) if treat_AL !=.
egen st_median_age_90  = std(median_age_90) if treat_AL !=.
egen st_pop_density99  = std(pop_density99) if treat_AL !=.
egen st_pop_density90  = std(pop_density90) if treat_AL !=.
egen st_urban_rural99  = std(urban_rural99) if treat_AL !=.
egen st_out_wedlock90  = std(out_wedlock90) if treat_AL !=.
egen st_out_wedlock99  = std(out_wedlock99) if treat_AL !=.
egen st_single_parents90  = std(single_parents90) if treat_AL !=.
egen st_single_parents99  = std(single_parents99) if treat_AL !=.
egen st_share_bluecollar99  = std(share_bluecollar99) if treat_AL !=.
egen st_foreigner_share2006 = std(foreigner_share2006) if treat_AL !=.

egen st_share15_BAC99 = std(share15_BAC99) if treat_AL !=.
egen st_mean_age06 = std(mean_age06) if treat_AL !=.
egen st_share15_workers06 = std(share15_workers06) if treat_AL !=.
egen st_median_income08= std(median_income08) if treat_AL !=.
egen st_median_income01= std(median_income01) if treat_AL !=.
egen st_healthcare_pc = std(healthcare_pc) if treat_AL !=.
egen st_high_school_pc = std(high_school_pc) if treat_AL !=.
egen st_vocational_school_pc = std(vocational_school_pc) if treat_AL !=.
egen st_post_office_pc = std(post_office_pc) if treat_AL !=.

egen st_healthcare98 = std(healthcare98) if treat_AL !=.
egen st_high_school98 = std(high_school98) if treat_AL !=.
egen st_vocational_school98 = std(vocational_school98) if treat_AL !=.
egen st_post_office98 = std(post_office98) if treat_AL !=.

mat B=J(23,2,0)


local no = 1
quietly: rdrobust st_urban_rural99 distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) vce(cluster cant_ID)
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix B[`no', 1] =  b`no'
matrix B[`no', 2] =  s`no'
local no = `no'+1
quietly: rdrobust st_pop_density90 distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) vce(cluster cant_ID) 
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix B[`no', 1] =  b`no'
matrix B[`no', 2] =  s`no'
local no = `no'+1
quietly: rdrobust st_pop_density99 distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) vce(cluster cant_ID) 
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix B[`no', 1] =  b`no'
matrix B[`no', 2] =  s`no'
local no = `no'+1 
quietly: rdrobust st_mean_age_90 distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) vce(cluster cant_ID)
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix B[`no', 1] =  b`no'
matrix B[`no', 2] =  s`no'
local no = `no'+1 
quietly: rdrobust st_mean_age_99 distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) vce(cluster cant_ID)
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix B[`no', 1] =  b`no'
matrix B[`no', 2] =  s`no'
local no = `no'+1 
quietly: rdrobust st_mean_age06 distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) vce(cluster cant_ID)
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix B[`no', 1] =  b`no'
matrix B[`no', 2] =  s`no'
local no = `no'+1 
quietly: rdrobust st_foreigner_share2006 distance2 if treat_AL !=., rho(1) masspoints(off) kernel(uni) covs($distances $segment2) vce(cluster cant_ID)
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix B[`no', 1] =  b`no'
matrix B[`no', 2] =  s`no'
local no = `no'+1 
quietly: rdrobust st_share_bluecollar99 distance2 if treat_AL !=., rho(1) masspoints(off) kernel(uni) covs($distances $segment2) vce(cluster cant_ID)
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix B[`no', 1] =  b`no'
matrix B[`no', 2] =  s`no'
local no = `no'+1 
quietly: rdrobust st_share15_workers06 distance2 if treat_AL !=., rho(1) masspoints(off) kernel(uni) covs($distances $segment2) vce(cluster cant_ID)
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix B[`no', 1] =  b`no'
matrix B[`no', 2] =  s`no'
local no = `no'+1
quietly: rdrobust st_median_income01 distance2 if treat_AL !=., rho(1) masspoints(off) kernel(uni) covs($distances $segment2) vce(cluster cant_ID) 
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix B[`no', 1] =  b`no'
matrix B[`no', 2] =  s`no'
local no = `no'+1 
quietly: rdrobust st_median_income08 distance2 if treat_AL !=., rho(1) masspoints(off) kernel(uni) covs($distances $segment2) vce(cluster cant_ID) 
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix B[`no', 1] =  b`no'
matrix B[`no', 2] =  s`no'
local no = `no'+1 
quietly: rdrobust st_single_parents90 distance2 if treat_AL !=., rho(1) masspoints(off) kernel(uni) covs($distances $segment2) vce(cluster cant_ID)
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix B[`no', 1] =  b`no'
matrix B[`no', 2] =  s`no'
local no = `no'+1 
quietly: rdrobust st_single_parents99 distance2 if treat_AL !=., rho(1) masspoints(off) kernel(uni) covs($distances $segment2) vce(cluster cant_ID)
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix B[`no', 1] =  b`no'
matrix B[`no', 2] =  s`no'
local no = `no'+1 
quietly: rdrobust st_out_wedlock99 distance2 if treat_AL !=., rho(1) masspoints(off) kernel(uni) covs($distances $segment2) vce(cluster cant_ID)
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix B[`no', 1] =  b`no'
matrix B[`no', 2] =  s`no'
local no = `no'+1 
quietly: rdrobust st_out_wedlock99 distance2 if treat_AL !=., rho(1) masspoints(off) kernel(uni) covs($distances $segment2) vce(cluster cant_ID)
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix B[`no', 1] =  b`no'
matrix B[`no', 2] =  s`no'
local no = `no'+1
quietly: rdrobust st_healthcare98 distance2 if treat_AL !=., rho(1) masspoints(off) kernel(uni) covs($distances $segment2) vce(cluster cant_ID) 
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix B[`no', 1] =  b`no'
matrix B[`no', 2] =  s`no'
local no = `no'+1
quietly: rdrobust st_healthcare_pc distance2 if treat_AL !=., rho(1) masspoints(off) kernel(uni) covs($distances $segment2) vce(cluster cant_ID) 
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix B[`no', 1] =  b`no'
matrix B[`no', 2] =  s`no'
local no = `no'+1
quietly: rdrobust st_high_school98 distance2 if treat_AL !=., rho(1) masspoints(off) kernel(uni) covs($distances $segment2) vce(cluster cant_ID)
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix B[`no', 1] =  b`no'
matrix B[`no', 2] =  s`no'
local no = `no'+1
quietly: rdrobust st_high_school_pc distance2 if treat_AL !=., rho(1) masspoints(off) kernel(uni) covs($distances $segment2) vce(cluster cant_ID)
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix B[`no', 1] =  b`no'
matrix B[`no', 2] =  s`no'
local no = `no'+1
quietly: rdrobust st_vocational_school98 distance2 if treat_AL !=., rho(1) masspoints(off) kernel(uni) covs($distances $segment2) vce(cluster cant_ID)
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix B[`no', 1] =  b`no'
matrix B[`no', 2] =  s`no'
local no = `no'+1
quietly: rdrobust st_vocational_school_pc distance2 if treat_AL !=., rho(1) masspoints(off) kernel(uni) covs($distances $segment2) vce(cluster cant_ID)
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix B[`no', 1] =  b`no'
matrix B[`no', 2] =  s`no'
local no = `no'+1
quietly: rdrobust st_post_office98 distance2 if treat_AL !=., rho(1) masspoints(off) kernel(uni) covs($distances $segment2) vce(cluster cant_ID)
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix B[`no', 1] =  b`no'
matrix B[`no', 2] =  s`no'
local no = `no'+1
quietly: rdrobust st_post_office_pc distance2 if treat_AL !=., rho(1) masspoints(off) kernel(uni) covs($distances $segment2) vce(cluster cant_ID)
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix B[`no', 1] =  b`no'
matrix B[`no', 2] =  s`no'


coefplot matrix(B[,1]), se(B[,2]) xline(0, lcolor(black)) /// 
coeflabels(r1 = "Urban municipality (1999)" r2 = "Population density (1990)" r3 = "Population density (1999)" r4 = "Age (1990)" r5 = "Age (1999)" r6 = "Age (2006)" r7="Foreign residents (2006)" r8 = "Employment (1999)" r9 = "Employment (2006)" r10= "Income (2001)" r11= "Income (2008)" r12 = "Single parents (1990)" r13 = "Single parents (1999)"  r14 = "Non-married parents (1990)" r15 = "Non-married parents (1999)" r16 = "Health Care (1998)" r17 = "Health Care (2013)" r18 = "High School (1998)" r19 = "High School (2013)" r20 = "Vocational School (1998)" r21 = "Vocational School (2013)" r22 = "Post Office (1998)" r23 = "Post Office (2013)") xtitle("Coefficient (standardized)" , ///
color(black) margin(medium)) levels(95) ciopts(lcolor(black) lstyle(p15)) msize(medium)  graphregion(color(white)) xlabel(-1 -0.8 -0.6 -0.4  -0.2  0  0.2  0.4 0.6 0.8 1, nogrid)   

graph export "..\Paper EU Identity\Graphs\coefplot_rob_2add.tif", replace width(3000) height(2000)
graph export "..\Paper EU Identity\Graphs\coefplot_rob_2add.png", replace width(3000) height(2000)
graph export "..\Paper EU Identity\Graphs\coefplot_rob_2add.pdf", replace 

estimates drop _all


********************************************************************************
*********   Table C.1 Mechanisms: Stronger European Identity  ******************
********************************************************************************

use "processed data\oip_attachment.dta", clear
eststo: reg st_attachement_europe is_aslr age gender employmentstatus diplome if treat_AL!=., r
*eststo: reg st_EuropeVSFrance is_aslr age gender employmentstatus diplome if treat_AL!=., r
eststo: reg st_attachement_france is_aslr age gender employmentstatus diplome if treat_AL!=., r
esttab using "..\Paper EU Identity\Tables\ID_Table_attach1.tex", fragment booktabs nostar replace cells(b(star fmt(3) nostar) se(par(( )) abs fmt(3)) p(par({[ ]}) abs fmt(3))) drop(_cons age gender employmentstatus diplome) ///
				mlabel(none) style(fixed) collabels(none) nolines nogaps nonumbers postfoot(\hline) varlabel(is_aslr "Treatment vs. Control")  /*prehead("")*/ ///
				stats( N, fmt( 0) label( "Observations")) noabbr 
estimates drop _all

use "processed data\oip_euroCitizen.dta", clear

eststo: reg st_Euro_citizen is_aslr age gender employmentstatus diplome if treat_AL!=., r

use "processed data\oip_EUR_pride.dta", clear

eststo: reg st_EUR_pride is_aslr age gender employmentstatus diplome if treat_AL!=., r

esttab using "..\Paper EU Identity\Tables\ID_Table_opinions2_1.tex", fragment booktabs nostar replace cells(b(star fmt(3) nostar) se(par(( )) abs fmt(3)) p(par({[ ]}) abs fmt(3))) drop(_cons age gender employmentstatus diplome) ///
				mlabel(none) style(fixed) collabels(none) nolines nogaps nonumbers postfoot(\hline) varlabel(is_aslr "Treatment vs. Control")  /*prehead("")*/ ///
				stats( N, fmt( 0) label( "Observations")) noabbr 
estimates drop _all


********************************************************************************
*********   Table C.2 Differences in European Identity and Perceived Economic Benefits  ******************
********************************************************************************

estimates drop _all
use "processed data\oip_citizen_CM_fav.dta", clear
estimates drop _all

gen interaction = c.st_future_MU_reg_economie#is_aslr
eststo: reg st_european_citizen st_future_MU_reg_economie is_aslr interaction age gender employmentstatus diplome if treat_AL!=., r

use "processed data\oip_attach_EU.dta", clear

gen interaction = c.st_realization_EU_Reg#is_aslr
eststo: reg st_attachement_europe st_realization_EU_Reg is_aslr interaction  age gender employmentstatus diplome if treat_AL!=., r

use "processed data\oip_regions_EUR_pride.dta", clear

gen interaction = c.st_coop_reg_EU#is_aslr
eststo: reg st_EUR_pride st_coop_reg_EU is_aslr interaction age gender employmentstatus diplome if treat_AL!=., r

esttab using "..\Paper EU Identity\Tables\ID_Table_EUR_dev_REG.tex", fragment booktabs nostar replace cells(b(star fmt(3) nostar) se(par(( )) abs fmt(3)) p(par({[ ]}) abs fmt(3))) drop(_cons age gender employmentstatus diplome) order(is_aslr  st_future_MU_reg_economie st_realization_EU_Reg st_coop_reg_EU  interaction)  ///
				mlabel(none) style(fixed) collabels(none) nolines nogaps nonumbers postfoot(\hline) varlabel(st_realization_EU_Reg " - EU Impact " st_future_MU_reg_economie " - Common Market" st_coop_reg_EU " - Interregional cooperation in EU" is_aslr "Treatment vs. Control" interaction "Interaction")  /*prehead("")*/ ///
				stats( N, fmt(0) label("Observations")) noabbr 
estimates drop _all
drop interaction 


*******************************************************************************************************
*********  Table C.3 Nested Identities: EU, National, and Regional Level (Alsace & Lorraine)  *********
*******************************************************************************************************

use "processed data\oip_attachment.dta", clear

eststo: reg st_attachement_region is_aslr age gender employmentstatus diplome if treat_AL!=., r
eststo: reg st_attachement_france is_aslr age gender employmentstatus diplome if treat_AL!=., r
eststo: reg st_attachement_europe is_aslr age gender employmentstatus diplome if treat_AL!=., r
esttab using "..\Paper EU Identity\Tables\ID_Table_opinions1_1.tex", fragment booktabs nostar replace cells(b(star fmt(3) nostar) se(par(( )) abs fmt(3)) p(par({[ ]}) abs fmt(3))) drop(_cons age gender employmentstatus diplome) ///
				mlabel(none) style(fixed) collabels(none) nolines nogaps nonumbers postfoot(\hline) varlabel(is_aslr "Treatment vs. Control")  /*prehead("")*/ ///
				stats( N, fmt( 0) label( "Observations")) noabbr 
estimates drop _all

use "processed data\oip_attachment.dta", clear

tab ID_2, gen(dep_dummy)

gen treated_all = 0 
replace treated_all = 1 if is_aslr == 1 

gen ID = st_attachement_france
gen interaction = c.ID#treated_all 
eststo: reg st_attachement_region ID treated_all interaction age gender employmentstatus diplome dep_dummy1-dep_dummy85 if treat_AL !=. , r
replace ID = st_attachement_europe
replace interaction = c.ID#treated_all 
eststo: reg st_attachement_france ID treated_all interaction age gender employmentstatus diplome  dep_dummy1-dep_dummy85 if treat_AL !=. , r
replace ID = st_attachement_region
replace interaction = c.ID#treated_all 
eststo: reg st_attachement_europe ID treated_all interaction age gender employmentstatus diplome dep_dummy1-dep_dummy85 if treat_AL !=. , r
esttab using "..\Paper EU Identity\Tables\ID_Table_complementarity6_2.tex", fragment booktabs nostar replace cells(b(star fmt(3) nostar) se(par(( )) abs fmt(3)) p(par({[ ]}) abs fmt(3))) drop(_cons ID treated_all age gender employmentstatus diplome dep_dummy*) order(interaction) ///
				mlabel(none) style(fixed) collabels(none) nolines nogaps nonumbers postfoot(\hline) varlabel (interaction "V.o.I. X Treatment vs. Control")  ///
				stats(N, fmt(0) label("Observations")) noabbr 
estimates drop _all
drop interaction
drop ID

use "processed data\oip_dev_planning.dta", clear
estimates drop _all
eststo: reg st_Reg_dev_plan is_aslr age gender employmentstatus diplome if treat_AL != ., r
eststo: reg st_Nat_dev_plan is_aslr age gender employmentstatus diplome if treat_AL != ., r
eststo: reg st_EU_dev_plan is_aslr age gender employmentstatus diplome if treat_AL != ., r
esttab using "..\Paper EU Identity\Tables\ID_Table_dev_plan1.tex", fragment booktabs nostar replace cells(b(star fmt(3) nostar) se(par(( )) abs fmt(3)) p(par({[ ]}) abs fmt(3))) drop(_cons age gender employmentstatus diplome) ///
				mlabel(none) style(fixed) collabels(none) nolines nogaps nonumbers postfoot(\hline) varlabel(is_aslr "Treatment vs. Control")  /*prehead("")*/ ///
				stats( N, fmt( 0) label(  "Observations")) noabbr 
estimates drop _all

** Relative

eststo: reg st_Reg_Nat_dev_plan is_aslr age gender employmentstatus diplome if treat_AL != ., r
eststo: reg st_Nat_EU_dev_plan is_aslr age gender employmentstatus diplome if treat_AL != ., r
eststo: reg st_EU_Reg_dev_plan is_aslr age gender employmentstatus diplome if treat_AL != ., r
esttab using "..\Paper EU Identity\Tables\ID_Table_dev_plan2.tex", fragment booktabs nostar replace cells(b(star fmt(3) nostar) se(par(( )) abs fmt(3)) p(par({[ ]}) abs fmt(3))) drop(_cons age gender employmentstatus diplome) ///
				mlabel(none) style(fixed) collabels(none) nolines nogaps nonumbers postfoot(\hline) varlabel(is_aslr "Treatment vs. Control")  /*prehead("")*/ ///
				stats( N, fmt( 0) label(  "Observations")) noabbr 
estimates drop _all


*************************************************************************************************
*********   Table C.4 Identities as Substitutes (All of France w/o Alsace & Lorraine)  **********
*************************************************************************************************


use "processed data\oip_attachment.dta", clear

tab ID_2, gen(dep_dummy)
tab year, gen(year_dummy)

gen ID = st_attachement_france3
eststo: reg st_attachement_region3 ID  age gender employmentstatus diplome if treat_AL == ., r
replace ID = st_attachement_europe3
eststo: reg st_attachement_france3  ID age gender employmentstatus diplome if treat_AL == ., r
replace ID = st_attachement_region3
eststo: reg st_attachement_europe3 ID age gender employmentstatus diplome if treat_AL == ., r
esttab using "..\Paper EU Identity\Tables\ID_Table_complementarity_1", fragment booktabs nostar replace cells(b(star fmt(3) nostar) se(par(( )) abs fmt(3)) p(par({[ ]}) abs fmt(3))) drop(_cons age gender employmentstatus diplome) ///
				mlabel(none) style(fixed) collabels(none) nolines nogaps nonumbers postfoot(\hline) varlabel(ID "Variable of Interest")  /*prehead("")*/ ///
				stats(N, fmt(0) label("Observations")) noabbr 
estimates drop _all
drop ID


gen ID = st_attachement_france3
eststo: reg st_attachement_region3 ID  age gender employmentstatus diplome dep_dummy1-dep_dummy85 year_dummy1-year_dummy3  if treat_AL == ., r
replace ID = st_attachement_europe3
eststo: reg st_attachement_france3  ID age gender employmentstatus diplome dep_dummy1-dep_dummy85 year_dummy1-year_dummy3  if treat_AL == ., r
replace ID = st_attachement_region3
eststo: reg st_attachement_europe3 ID age gender employmentstatus diplome dep_dummy1-dep_dummy85 year_dummy1-year_dummy3  if treat_AL == ., r
esttab using "..\Paper EU Identity\Tables\ID_Table_complementarity_2", fragment booktabs nostar replace cells(b(star fmt(3) nostar) se(par(( )) abs fmt(3)) p(par({[ ]}) abs fmt(3))) drop(_cons age gender employmentstatus diplome dep_dummy* year_dummy*) ///
				mlabel(none) style(fixed) collabels(none) nolines nogaps nonumbers postfoot(\hline) varlabel(ID "Variable of Interest")  /*prehead("")*/ ///
				stats(N, fmt(0) label("Observations")) noabbr 
estimates drop _all
drop ID


use "processed data\oip_attachment.dta", clear


collapse st_attachement_france3 st_attachement_region3 st_attachement_europe3 age gender employmentstatus diplome treat_AL, by(ID_2 year)

gen ID = st_attachement_france3
eststo: reg st_attachement_region3 ID  age gender employmentstatus diplome if treat_AL == ., r
replace ID = st_attachement_europe3
eststo: reg st_attachement_france3  ID age gender employmentstatus diplome if treat_AL == ., r
replace ID = st_attachement_region3
eststo: reg st_attachement_europe3 ID age gender employmentstatus diplome if treat_AL == ., r
esttab using "..\Paper EU Identity\Tables\ID_Table_complementarity_3", fragment booktabs nostar replace cells(b(star fmt(3) nostar) se(par(( )) abs fmt(3)) p(par({[ ]}) abs fmt(3))) drop(_cons age gender employmentstatus diplome) ///
				mlabel(none) style(fixed) collabels(none) nolines nogaps nonumbers postfoot(\hline) varlabel(ID "Variable of Interest")  /*prehead("")*/ ///
				stats(N, fmt(0) label("Observations")) noabbr 
estimates drop _all
drop ID

use "processed data\oip_attachment.dta", clear

collapse st_attachement_france3 st_attachement_region3 st_attachement_europe3 age gender employmentstatus diplome treat_AL, by(ID_2 year)

tab ID_2, gen(dep_dummy)

tab year, gen(year_dummy)

xtset ID_2 year, del(2)

gen ID = st_attachement_france3
eststo: xtreg st_attachement_region3 ID age gender employmentstatus diplome year_dummy1-year_dummy3 if treat_AL == ., fe r
replace ID = st_attachement_europe3
eststo: xtreg st_attachement_france3 ID age gender employmentstatus diplome year_dummy1-year_dummy3 if treat_AL == ., fe r
replace ID = st_attachement_region3
eststo: xtreg st_attachement_europe3 ID age gender employmentstatus diplome year_dummy1-year_dummy3 if treat_AL == ., fe r
esttab using "..\Paper EU Identity\Tables\ID_Table_complementarity_4.tex", fragment booktabs nostar replace cells(b(star fmt(3) nostar) se(par(( )) abs fmt(3)) p(par({[ ]}) abs fmt(3))) drop(_cons age gender employmentstatus diplome  year_dummy1 year_dummy2 year_dummy3) ///
				mlabel(none) style(fixed) collabels(none) nolines nogaps nonumbers postfoot(\hline) varlabel(ID "Variable of Interest")  /*prehead("")*/ ///
				stats(N, fmt(0) label("Observations")) noabbr 
estimates drop _all
drop ID


********************************************************************************
*********   Figure C.3 Regionalist Parties in Regional Elections 2015  *********
********************************************************************************

use "processed data\reshaped_letter_AlsaceLorraine.dta", clear
estimates drop _all
drop if insee_code == 1

keep if year == 1992 | year == 2005 | year == 1994 | year == 1999 | year == 2004

gen cant_ID = ID_2*1000+ID_3

gen distance_robust_border2 = distance_robust_border/1000
replace distance_robust_border2 = distance_robust_border2*-1 if row_dum2 == 0

gen is_oldmoselle = FE_moselle
replace is_oldmoselle = 0 if FE_meurthe ==1
replace is_oldmoselle = . if FE_moselle != 1 & FE_meurthe !=1

gen distance_old_meu_mos = dist_old_border
replace distance_old_meu_mos = dist_old_border * -1 if is_oldmoselle == 0
replace distance_old_meu_mos = . if is_oldmoselle == .

gen distance_old_meu_mos2 = distance_old_meu_mos/1000

gen is_borderingAL = 0 if treat_AL == 0
replace is_borderingAL = 1 if ID_2 == 8 | ID_2 == 51 | ID_2 == 52 | ID_2 == 70 

gen distance_france = dist_AL_restFRA
replace distance_france = distance_france * -1 if is_borderingAL == 1
replace distance_france = . if is_borderingAL == .

gen distance_france2 = distance_france/1000


gen dist_limited = distance_limited
replace dist_limited = distance_limited*-1 if treat_AL == 0
gen dist_limited2 = dist_limited/1000


****************************************************************
******** Robustness: Shorter Border Regionalist parties ********
****************************************************************

mat C=J(2,2,0)

local no = 1
rdrobust reg15VoixExpLREG distance2 if treat_AL !=. , rho(1) kernel(uni) masspoints(off) covs($distances) vce(cluster cant_ID) h(16.179)
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix C[`no', 1] =  b`no'
matrix C[`no', 2] =  s`no'
local no = `no'+1
rdrobust reg15VoixExpLREG dist_limited2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances) vce(cluster cant_ID) h(22.430)
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix C[`no', 1] =  b`no'
matrix C[`no', 2] =  s`no'
coefplot matrix(C[,1]), se(C[,2]) xline(0, lcolor(black)) msize(medium) xlabel(-2 0 2 4 6) xscale(range(-4 8))  /// 
coeflabels(r1 = "Baseline" r2 = "Modified", labsize(medium)) levels(90) ciopts(lcolor(black) lstyle(p15)) graphregion(color(white)) headings(r1 = "{bf:Regionalist parties}", labsize(medlarge)) xlabel( -2 0 2 4 6, nogrid)

graph export "..\Paper EU Identity\Graphs\coefplot_treatborderlimited_regionalist.tif", replace width(3000) height(2000)
graph export "..\Paper EU Identity\Graphs\coefplot_treatborderlimited_regionalist.png", replace width(3000) height(2000)
graph export "..\Paper EU Identity\Graphs\coefplot_treatborderlimited_regionalist.pdf", replace
estimates drop _all


********************************************************************************
*********   Table D.1 RD Smoothness Test: Pre-Treatment Variables  *************
********************************************************************************

use "processed data\letter_AlsaceLorraine.dta",clear

gen cant_ID = ID_2*1000+ID_3

estimates drop _all

eststo: rdrobust sui_brl distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) vce(cluster cant_ID) h(10)
estadd local Obs = e(N_h_r) + e(N_h_l)  
eststo: rdrobust sui_whe distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) vce(cluster cant_ID) h(10)
estadd local Obs = e(N_h_r) + e(N_h_l)  
eststo: rdrobust sui_wpo distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) vce(cluster cant_ID)
estadd local Obs = e(N_h_r) + e(N_h_l)  
eststo: rdrobust sui_oni distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) vce(cluster cant_ID) h(10)
estadd local Obs = e(N_h_r) + e(N_h_l)  
eststo: rdrobust sui_sfl distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) vce(cluster cant_ID) h(10)
estadd local Obs = e(N_h_r) + e(N_h_l)  
esttab using "..\Paper EU Identity\Tables\ID_Table_10_geo1.tex", fragment booktabs nostar replace cells(b(star fmt(3) nostar) se(par(( )) abs fmt(3)) p(par({[ ]}) abs fmt(3))) ///
				mlabel(none) style(fixed) collabels(none) nolines nogaps nonumbers postfoot(\hline) varlabel(RD_Estimate "Treatment vs. Control") ///
				stats(h_r Obs, fmt(3 0) label("Bandwidth (km)" "Observations")) noabbr 
estimates drop _all				
				
eststo: rdrobust er_elev distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) vce(cluster cant_ID)
estadd local Obs = e(N_h_r) + e(N_h_l)  
eststo: rdrobust st_dev_elev distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) vce(cluster cant_ID)
estadd local Obs = e(N_h_r) + e(N_h_l)  
eststo: rdrobust er_rug distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) vce(cluster cant_ID)
estadd local Obs = e(N_h_r) + e(N_h_l)  
eststo: rdrobust p1866 distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) vce(cluster cant_ID)
estadd local Obs = e(N_h_r) + e(N_h_l)  
eststo: rdrobust popdens_1866 distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) vce(cluster cant_ID)
estadd local Obs = e(N_h_r) + e(N_h_l)  
esttab using "..\Paper EU Identity\Tables\ID_Table_10_geo2.tex", fragment booktabs nostar replace cells(b(star fmt(3) nostar) se(par(( )) abs fmt(3)) p(par({[ ]}) abs fmt(3))) ///
				mlabel(none) style(fixed) collabels(none) nolines nogaps nonumbers postfoot(\hline) varlabel(RD_Estimate "Treatment vs. Control") ///
				stats(h_r Obs, fmt(3 0) label("Bandwidth (km)" "Observations")) noabbr 
estimates drop _all

eststo: rdrobust river_length distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) vce(cluster cant_ID)
estadd local Obs = e(N_h_r) + e(N_h_l)  
eststo: rdrobust road_length distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) vce(cluster cant_ID)
estadd local Obs = e(N_h_r) + e(N_h_l)  
eststo: rdrobust LU_grazing_1860 distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) vce(cluster cant_ID) h(10)
estadd local Obs = e(N_h_r) + e(N_h_l)  
eststo: rdrobust LU_cropland_1860 distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) vce(cluster cant_ID) h(10)
estadd local Obs = e(N_h_r) + e(N_h_l)  
esttab using "..\Paper EU Identity\Tables\ID_Table_10_geo3.tex", fragment booktabs nostar replace cells(b(star fmt(3) nostar) se(par(( )) abs fmt(3)) p(par({[ ]}) abs fmt(3))) ///
				mlabel(none) style(fixed) collabels(none) nolines nogaps nonumbers postfoot(\hline) varlabel(RD_Estimate "Treatment vs. Control") ///
				stats(h_r Obs, fmt(3 0) label("Bandwidth (km)" "Observations")) noabbr 
estimates drop _all

eststo: rdrobust gare_1860 distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) vce(cluster cant_ID)
estadd local Obs = e(N_h_r) + e(N_h_l)  
eststo: rdrobust hie_1860 distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) vce(cluster cant_ID)
estadd local Obs = e(N_h_r) + e(N_h_l)  
esttab using "..\Paper EU Identity\Tables\ID_Table_10_geo4.tex", fragment booktabs nostar replace cells(b(star fmt(3) nostar) se(par(( )) abs fmt(3)) p(par({[ ]}) abs fmt(3))) ///
				mlabel(none) style(fixed) collabels(none) nolines nogaps nonumbers postfoot(\hline) varlabel(RD_Estimate "Treatment vs. Control") ///
				stats(h_r Obs, fmt(3 0) label("Bandwidth (km)" "Observations")) noabbr 
estimates drop _all


*******************************************************************************************************
*********   Table D.2 RD Smoothness Test: 1860 Economonic Indicators (Level of Arrondisment)  *********
*******************************************************************************************************

use "processed data\industry_collapsed_arrondisment.dta",clear // only Lorraine (and not all arrondisments

estimates drop _all

codebook 
egen st_income_male = std(Salairedeshommes)
egen st_child_share = std(child_share)
egen st_income_pc = std(income_pc)
egen st_productivity =std(productivity)
egen st_male_productivity = std(male_productivity)
egen st_workers_per_firm = std(workers_per_firm)
egen st_male_workers_per_firm = std(male_workers_per_firm)
egen st_firm_productivity = std(firm_productivity)
 
eststo: reg st_child_share treatment 
eststo: reg st_income_pc treatment 
eststo: reg st_productivity treatment 
eststo: reg st_firm_productivity treatment 

esttab using "..\Paper EU Identity\Tables\ID_Table_smooth_industry.tex", fragment booktabs nostar replace cells(b(star fmt(3) nostar) se(par(( )) abs fmt(3)) p(par({[ ]}) abs fmt(3))) keep(treatment) ///
				mlabel(none) style(fixed) collabels(none) nolines nogaps nonumbers postfoot(\hline) varlabel(treatment "Treatment vs. Control") ///
				stats(N, fmt(0) label( "Observations")) noabbr 
estimates drop _all

mat W = J(4,3,.)
global num = 1
foreach x in child_share income_pc productivity firm_productivity {
sum `x' if treatment == 1
mat W[$num ,1] =  r(mean)
sum `x' if treatment == 0
mat W[$num ,2] =  r(mean)
reg `x' treatment 
mat W[$num ,3] = 2*ttail(e(df_r), abs(_b[treatment]/_se[treatment]))
global num = $num +1
}
	
write_mats W using "..\Paper EU Identity\Tables\ID_Table_ttest_industry.tex", ///
	names(`" "Share Children" "Income PC" "Worker Productivity" "Firm Productivity" "Firm Size"  "') ///
	ndecimals(3) 

matrix list W


********************************************************************************
*********   Table D.3: Smoothness: Post-Treatment Variables  *******************
********************************************************************************


use "processed data\letter_AlsaceLorraine.dta",clear	

gen cant_ID = ID_2*1000+ID_3

estimates drop _all

gen change_46_36 = Population_1946 - Population_1936
gen change_46_26 = Population_1946 - Population_1926
gen change_46_16 =  Population_1946 - Population_1916
gen change_1946_1866 = Population_1946 - p1866

eststo: rdrobust change_1946_1866 distance2 if treat_AL !=. , rho(1) kernel(uni) masspoints(off) covs($distances $segment2) vce(cluster cant_ID) h(10) 
estadd local Obs = e(N_h_r) + e(N_h_l) 
eststo: rdrobust change_46_16 distance2 if treat_AL !=. , rho(1) kernel(uni) masspoints(off) covs($distances $segment2) vce(cluster cant_ID) 
estadd local Obs = e(N_h_r) + e(N_h_l) 
eststo: rdrobust change_46_26 distance2 if treat_AL !=. , rho(1) kernel(uni) masspoints(off) covs($distances $segment2) vce(cluster cant_ID) 
estadd local Obs = e(N_h_r) + e(N_h_l)
eststo: rdrobust change_46_36 distance2 if treat_AL !=. , rho(1) kernel(uni) masspoints(off) covs($distances $segment2) vce(cluster cant_ID)
estadd local Obs = e(N_h_r) + e(N_h_l) 
esttab using "..\Paper EU Identity\Tables\ID_Table_hist_change_pop.tex", fragment booktabs nostar replace cells(b(star fmt(3) nostar) se(par([ ]) abs fmt(3)) p(par({ }) abs fmt(3)))  ///
				mlabel(none) style(fixed) collabels(none) nolines nogaps nonumbers postfoot(\hline) varlabel(RD_Estimate "Coefficient") ///
				stats(h_r Obs, fmt(3 0) label("Bandwidth (km)" "Observations")) noabbr 
estimates drop _all	

	
eststo: rdrobust share15_BAC99 distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) vce(cluster cant_ID)
estadd local Obs = e(N_h_r) + e(N_h_l)
eststo: rdrobust mean_age06 distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) vce(cluster cant_ID) 
estadd local Obs = e(N_h_r) + e(N_h_l)
eststo: rdrobust share15_workers06 distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) vce(cluster cant_ID) 
estadd local Obs = e(N_h_r) + e(N_h_l)
eststo: rdrobust median_income08 distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) vce(cluster cant_ID)
estadd local Obs = e(N_h_r) + e(N_h_l)
esttab using "..\Paper EU Identity\Tables\ID_Table_socio1.tex", fragment booktabs nostar replace cells(b(star fmt(3) nostar) se(par(( )) abs fmt(3)) p(par({[ ]}) abs fmt(3))) ///
				mlabel(none) style(fixed) collabels(none) nolines nogaps nonumbers postfoot(\hline) varlabel(RD_Estimate "Treatment vs. Control") ///
				stats(h_r Obs, fmt(3 0) label("Bandwidth (km)" "Observations")) noabbr 
				
estimates drop _all
				

eststo: rdrobust healthcare_pc distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) vce(cluster cant_ID)
estadd local Obs = e(N_h_r) + e(N_h_l)
eststo: rdrobust high_school_pc distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) vce(cluster cant_ID)
estadd local Obs = e(N_h_r) + e(N_h_l)
eststo: rdrobust vocational_school_pc distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) vce(cluster cant_ID)
estadd local Obs = e(N_h_r) + e(N_h_l)
eststo: rdrobust post_office_pc distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) vce(cluster cant_ID)  h(10) 
estadd local Obs = e(N_h_r) + e(N_h_l)
esttab using "..\Paper EU Identity\Tables\ID_Table_socio2.tex", fragment booktabs nostar replace cells(b(star fmt(3) nostar) se(par(( )) abs fmt(3)) p(par({[ ]}) abs fmt(3))) ///
				mlabel(none) style(fixed) collabels(none) nolines nogaps nonumbers postfoot(\hline) varlabel(RD_Estimate "Treatment vs. Control") ///
				stats(h_r Obs, fmt(3 0) label("Bandwidth (km)" "Observations")) noabbr 
				
estimates drop _all

********************************************************************************
*********   Table D.4 RD Specification - Turnout Referendum 1992 & 2005  *******
********************************************************************************

estimates drop _all

use "processed data\letter_AlsaceLorraine.dta", clear
estimates drop _all
drop if insee_code == 1

gen cant_ID = ID_2*1000+ID_3

eststo: rdrobust Turnout1992 distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2 ) vce(cluster cant_ID) h(10)
estadd local Obs = e(N_h_r) + e(N_h_l) 
eststo: rdrobust Turnout1992 distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2 ) vce(cluster cant_ID)
estadd local Obs = e(N_h_r) + e(N_h_l)
eststo: rdrobust Turnout2005 distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2 ) vce(cluster cant_ID) h(10)
estadd local Obs = e(N_h_r) + e(N_h_l) 
eststo: rdrobust Turnout2005 distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2 ) vce(cluster cant_ID)
estadd local Obs = e(N_h_r) + e(N_h_l)  
esttab using "..\Paper EU Identity\Tables\ID_Table_turnout_final.tex", fragment booktabs nostar replace cells(b(star fmt(3) nostar) se(par(( )) abs fmt(3)) p(par({[ ]}) abs fmt(3)))  ///
				mlabel(none) style(fixed) collabels(none) nolines nogaps nonumbers varlabel(RD_Estimate "Treatment vs. Control") ///
				stats(h_r Obs, fmt(3 0) label("Bandwidth (km)" "Observations")) noabbr 

estimates drop _all

gen ymean = Turnout1992

eststo: estpost sum ymean if treat_AL !=. & distance2 > -10 & distance2 < 10, meanonly
eststo: estpost sum ymean if treat_AL !=. & distance2 > -12.234    & distance2 < 12.234   , meanonly


replace ymean = Turnout2005 

eststo: estpost sum ymean if treat_AL !=. & distance2 > -10 & distance2 < 10, meanonly
eststo: estpost sum ymean if treat_AL !=. & distance2 > -15.616      & distance2 < 15.616   , meanonly

esttab using "..\Paper EU Identity\Tables\ID_Table_main_turnout_final_ymean.tex", cells("mean(fmt(2))") nomtitles collabels(none) fragment postfoot(\hline) nolines nogaps nonumbers booktabs noobs compress label replace varlabel(ymean "Mean of Outcome") 
estimates drop _all
drop ymean

****************************************************************************************
*********   Table D.5 OLS Results - EU Support and Euroscepticism (1992 - 2005)  *******
****************************************************************************************

estimates drop _all
use "processed data\letter_AlsaceLorraine.dta",clear

gen cant_ID = ID_2*1000+ID_3

eststo: reg r92_yf treat_AL $distances $segment2 if treat_AL !=., cluster(cant_ID) r

eststo: reg r05_yf treat_AL $distances $segment2 if treat_AL !=., cluster(cant_ID) r


use "processed data\reshaped_letter_AlsaceLorraine.dta",clear

keep if year == 1992 | year == 2005

gen cant_ID = ID_2*1000+ID_3

eststo: reg yes_share treat_AL $distances $segment2 if treat_AL !=., cluster(cant_ID) r

esttab using "..\Paper EU Identity\Tables\ID_Table_main_OLS.tex", fragment booktabs nostar replace cells(b(star fmt(3) nostar) se(par(( )) abs fmt(3)) p(par({[ ]}) abs fmt(3)))  ///
				mlabel(none) style(fixed) collabels(none) nolines nogaps nonumbers varlabel(treat_AL "Treatment vs. Control") keep(treat_AL) ///
				stats(N, fmt(0) label("Observations")) noabbr 
				

				
use "processed data\letter_AlsaceLorraine.dta",clear
estimates drop _all

gen ymean = r92_yf

eststo: estpost sum ymean if treat_AL !=., meanonly

replace ymean = r05_yf

eststo: estpost sum ymean if treat_AL !=. , meanonly

use "processed data\reshaped_letter_AlsaceLorraine.dta",clear
keep if year == 1992 | year == 2005

gen ymean = yes_share

eststo: estpost sum ymean if treat_AL !=., meanonly

esttab using "..\Paper EU Identity\Tables\ID_Table_main_OLS_ymean.tex", cells("mean(fmt(2))") nomtitles collabels(none) fragment postfoot(\hline) nolines nogaps nonumbers booktabs noobs compress label replace varlabel(ymean "Mean of Outcome") 
estimates drop _all
drop ymean

estimates drop _all

use "processed data\reshaped_letter_AlsaceLorraine.dta", clear
estimates drop _all
drop if insee_code == 1

keep if year == 1994 | year == 1999 | year == 2004

gen cant_ID = ID_2*1000+ID_3

eststo: reg sum_EUvoteshare_neg treat_AL $distances $segment2 if treat_AL !=., cluster(cant_ID) r

eststo: reg sum_EUvoteshare_neg_noFN treat_AL $distances $segment2 if treat_AL !=., cluster(cant_ID) r

eststo: reg sum_weight_EUvoteshare_neg2_ treat_AL $distances $segment2 if treat_AL !=., cluster(cant_ID) r
esttab using "..\Paper EU Identity\Tables\ID_Table_eurosceptic_final_OLS.tex", fragment booktabs nostar replace cells(b(star fmt(3) nostar) se(par(( )) abs fmt(3)) p(par({[ ]}) abs fmt(3)))  ///
				mlabel(none) style(fixed) collabels(none) nolines nogaps nonumbers varlabel(treat_AL "Treatment vs. Control") keep(treat_AL) ///
				stats(N, fmt(0) label("Observations")) noabbr 

estimates drop _all

gen ymean = sum_EUvoteshare_neg

eststo: estpost sum ymean if treat_AL !=., meanonly


replace ymean = sum_EUvoteshare_neg_noFN 

eststo: estpost sum ymean if treat_AL !=., meanonly


replace ymean = sum_weight_EUvoteshare_neg2_

eststo: estpost sum ymean if treat_AL !=., meanonly

esttab using "..\Paper EU Identity\Tables\ID_Table_main_eurosceptic_final_OLS_ymean.tex", cells("mean(fmt(2))") nomtitles collabels(none) fragment postfoot(\hline) nolines nogaps nonumbers booktabs noobs compress label replace varlabel(ymean "Mean of Outcome") 
estimates drop _all
drop ymean


********************************************************************************
**************   Table D.6 RD Specification - No Controls  *********************
********************************************************************************

estimates drop _all
use "processed data\letter_AlsaceLorraine.dta",clear

gen cant_ID = ID_2*1000+ID_3

eststo: rdrobust r92_yf distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off)  vce(cluster cant_ID) h(10) 
estadd local Obs = e(N_h_r) + e(N_h_l) 
eststo: rdrobust r92_yf distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off)  vce(cluster cant_ID)
estadd local Obs = e(N_h_r) + e(N_h_l) 
eststo: rdrobust r05_yf distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off)  vce(cluster cant_ID) h(10) 
estadd local Obs = e(N_h_r) + e(N_h_l) 
eststo: rdrobust r05_yf distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off)  vce(cluster cant_ID) 
estadd local Obs = e(N_h_r) + e(N_h_l)  

use "processed data\reshaped_letter_AlsaceLorraine.dta",clear

keep if year == 1992 | year == 2005

gen cant_ID = ID_2*1000+ID_3

eststo: rdrobust yes_share distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) vce(cluster cant_ID) h(10) 
estadd local Obs = e(N_h_r) + e(N_h_l) 
eststo: rdrobust yes_share distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) vce(cluster cant_ID)
estadd local Obs = e(N_h_r) + e(N_h_l) 
esttab using "..\Paper EU Identity\Tables\ID_Table_main_nocontrols.tex", fragment booktabs nostar replace cells(b(star fmt(3) nostar) se(par(( )) abs fmt(3)) p(par({[ ]}) abs fmt(3)))  ///
				mlabel(none) style(fixed) collabels(none) nolines nogaps nonumbers varlabel(RD_Estimate "Treatment vs. Control") ///
				stats(h_r Obs, fmt(3 0) label("Bandwidth (km)" "Observations")) noabbr 
				
use "processed data\letter_AlsaceLorraine.dta",clear
estimates drop _all

gen ymean = r92_yf

eststo: estpost sum ymean if treat_AL !=. & distance2 > -10 & distance2 < 10, meanonly
eststo: estpost sum ymean if treat_AL !=. & distance2 > -19.866  & distance2 < 19.866 , meanonly

replace ymean = r05_yf

eststo: estpost sum ymean if treat_AL !=. & distance2 > -10 & distance2 < 10, meanonly
eststo: estpost sum ymean if treat_AL !=. & distance2 > -14.548   & distance2 < 14.548  , meanonly

use "processed data\reshaped_letter_AlsaceLorraine.dta",clear
keep if year == 1992 | year == 2005

gen ymean = yes_share

eststo: estpost sum ymean if treat_AL !=. & distance2 > -10 & distance2 < 10, meanonly
eststo: estpost sum ymean if treat_AL !=. & distance2 > -17.347   & distance2 < 17.347  , meanonly
esttab using "..\Paper EU Identity\Tables\ID_Table_main_ymean_nocontrols.tex", cells("mean(fmt(2))") nomtitles collabels(none) fragment postfoot(\hline) nolines nogaps nonumbers booktabs noobs compress label replace varlabel(ymean "Mean of Outcome") 
estimates drop _all
drop ymean

estimates drop _all

use "processed data\reshaped_letter_AlsaceLorraine.dta", clear
estimates drop _all
drop if insee_code == 1

keep if year == 1994 | year == 1999 | year == 2004

gen cant_ID = ID_2*1000+ID_3

eststo: rdrobust sum_EUvoteshare_neg distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) vce(cluster cant_ID) h(10)
estadd local Obs = e(N_h_r) + e(N_h_l) 
eststo: rdrobust sum_EUvoteshare_neg distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off)  vce(cluster cant_ID)
estadd local Obs = e(N_h_r) + e(N_h_l)
eststo: rdrobust sum_EUvoteshare_neg_noFN distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) vce(cluster cant_ID) h(10)
estadd local Obs = e(N_h_r) + e(N_h_l) 
eststo: rdrobust sum_EUvoteshare_neg_noFN distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) vce(cluster cant_ID)
estadd local Obs = e(N_h_r) + e(N_h_l)
eststo: rdrobust sum_weight_EUvoteshare_neg2_ distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off)  vce(cluster cant_ID) h(10)
estadd local Obs = e(N_h_r) + e(N_h_l) 
eststo: rdrobust sum_weight_EUvoteshare_neg2_ distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) vce(cluster cant_ID)
estadd local Obs = e(N_h_r) + e(N_h_l)   
esttab using "..\Paper EU Identity\Tables\ID_Table_eurosceptic_final_nocontrols.tex", fragment booktabs nostar replace cells(b(star fmt(3) nostar) se(par(( )) abs fmt(3)) p(par({[ ]}) abs fmt(3)))  ///
				mlabel(none) style(fixed) collabels(none) nolines nogaps nonumbers varlabel(RD_Estimate "Treatment vs. Control") ///
				stats(h_r Obs, fmt(3 0) label("Bandwidth (km)" "Observations")) noabbr 

estimates drop _all

gen ymean = sum_EUvoteshare_neg

eststo: estpost sum ymean if treat_AL !=. & distance2 > -10 & distance2 < 10, meanonly
eststo: estpost sum ymean if treat_AL !=. & distance2 > - 22.659     & distance2 <  22.659    , meanonly


replace ymean = sum_EUvoteshare_neg_noFN 

eststo: estpost sum ymean if treat_AL !=. & distance2 > -10 & distance2 < 10, meanonly
eststo: estpost sum ymean if treat_AL !=. & distance2 > -23.517     & distance2 < 23.517   , meanonly

replace ymean = sum_weight_EUvoteshare_neg2_

eststo: estpost sum ymean if treat_AL !=. & distance2 > -10 & distance2 < 10, meanonly
eststo: estpost sum ymean if treat_AL !=. & distance2 > -20.568       & distance2 < 20.568  , meanonly
esttab using "..\Paper EU Identity\Tables\ID_Table_main_eurosceptic_final_ymean_nocontrols.tex", cells("mean(fmt(2))") nomtitles collabels(none) fragment postfoot(\hline) nolines nogaps nonumbers booktabs noobs compress label replace varlabel(ymean "Mean of Outcome") 
estimates drop _all
drop ymean

********************************************************************************
**************   Table D.7 RD Specification - No Clusters  *********************
********************************************************************************

estimates drop _all
use "processed data\letter_AlsaceLorraine.dta",clear

gen cant_ID = ID_2*1000+ID_3

eststo: rdrobust r92_yf distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) h(10) 
estadd local Obs = e(N_h_r) + e(N_h_l) 
eststo: rdrobust r92_yf distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) 
estadd local Obs = e(N_h_r) + e(N_h_l) 
eststo: rdrobust r05_yf distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) h(10) 
estadd local Obs = e(N_h_r) + e(N_h_l) 
eststo: rdrobust r05_yf distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) h(10)
estadd local Obs = e(N_h_r) + e(N_h_l)  

use "processed data\reshaped_letter_AlsaceLorraine.dta",clear

keep if year == 1992 | year == 2005

gen cant_ID = ID_2*1000+ID_3

eststo: rdrobust yes_share distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) h(10) 
estadd local Obs = e(N_h_r) + e(N_h_l) 
eststo: rdrobust yes_share distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) 
estadd local Obs = e(N_h_r) + e(N_h_l) 
esttab using "..\Paper EU Identity\Tables\ID_Table_main_nocluster.tex", fragment booktabs nostar replace cells(b(star fmt(3) nostar) se(par(( )) abs fmt(3)) p(par({[ ]}) abs fmt(3)))  ///
				mlabel(none) style(fixed) collabels(none) nolines nogaps nonumbers varlabel(RD_Estimate "Treatment vs. Control") ///
				stats(h_r Obs, fmt(3 0) label("Bandwidth (km)" "Observations")) noabbr 
				
use "processed data\letter_AlsaceLorraine.dta",clear
estimates drop _all

gen ymean = r92_yf

eststo: estpost sum ymean if treat_AL !=. & distance2 > -10 & distance2 < 10, meanonly
eststo: estpost sum ymean if treat_AL !=. & distance2 > -15.369 & distance2 < 15.369 , meanonly

replace ymean = r05_yf

eststo: estpost sum ymean if treat_AL !=. & distance2 > -10 & distance2 < 10, meanonly
eststo: estpost sum ymean if treat_AL !=. & distance2 > -10   & distance2 < 10  , meanonly

use "processed data\reshaped_letter_AlsaceLorraine.dta",clear
keep if year == 1992 | year == 2005

gen ymean = yes_share

eststo: estpost sum ymean if treat_AL !=. & distance2 > -10 & distance2 < 10, meanonly
eststo: estpost sum ymean if treat_AL !=. & distance2 > -13.369   & distance2 < 13.369  , meanonly
esttab using "..\Paper EU Identity\Tables\ID_Table_main_ymean_nocluster.tex", cells("mean(fmt(2))") nomtitles collabels(none) fragment postfoot(\hline) nolines nogaps nonumbers booktabs noobs compress label replace varlabel(ymean "Mean of Outcome") 
estimates drop _all
drop ymean

estimates drop _all

use "processed data\reshaped_letter_AlsaceLorraine.dta", clear
estimates drop _all
drop if insee_code == 1

keep if year == 1994 | year == 1999 | year == 2004

gen cant_ID = ID_2*1000+ID_3

eststo: rdrobust sum_EUvoteshare_neg distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2)  h(10)
estadd local Obs = e(N_h_r) + e(N_h_l) 
eststo: rdrobust sum_EUvoteshare_neg distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) 
estadd local Obs = e(N_h_r) + e(N_h_l)
eststo: rdrobust sum_EUvoteshare_neg_noFN distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2)  h(10)
estadd local Obs = e(N_h_r) + e(N_h_l) 
eststo: rdrobust sum_EUvoteshare_neg_noFN distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) 
estadd local Obs = e(N_h_r) + e(N_h_l)
eststo: rdrobust sum_weight_EUvoteshare_neg2_ distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off)  covs($distances $segment2) h(10)
estadd local Obs = e(N_h_r) + e(N_h_l) 
eststo: rdrobust sum_weight_EUvoteshare_neg2_ distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) 
estadd local Obs = e(N_h_r) + e(N_h_l)   
esttab using "..\Paper EU Identity\Tables\ID_Table_eurosceptic_final_nocluster.tex", fragment booktabs nostar replace cells(b(star fmt(3) nostar) se(par(( )) abs fmt(3)) p(par({[ ]}) abs fmt(3)))  ///
				mlabel(none) style(fixed) collabels(none) nolines nogaps nonumbers varlabel(RD_Estimate "Treatment vs. Control") ///
				stats(h_r Obs, fmt(3 0) label("Bandwidth (km)" "Observations")) noabbr 

estimates drop _all

gen ymean = sum_EUvoteshare_neg

eststo: estpost sum ymean if treat_AL !=. & distance2 > -10 & distance2 < 10, meanonly
eststo: estpost sum ymean if treat_AL !=. & distance2 > -21.121    & distance2 <   21.121   , meanonly


replace ymean = sum_EUvoteshare_neg_noFN 

eststo: estpost sum ymean if treat_AL !=. & distance2 > -10 & distance2 < 10, meanonly
eststo: estpost sum ymean if treat_AL !=. & distance2 > -25.135      & distance2 <  25.135   , meanonly

replace ymean = sum_weight_EUvoteshare_neg2_

eststo: estpost sum ymean if treat_AL !=. & distance2 > -10 & distance2 < 10, meanonly
eststo: estpost sum ymean if treat_AL !=. & distance2 > -25.470      & distance2 < 25.470 , meanonly
esttab using "..\Paper EU Identity\Tables\ID_Table_main_eurosceptic_final_ymean_nocluster.tex", cells("mean(fmt(2))") nomtitles collabels(none) fragment postfoot(\hline) nolines nogaps nonumbers booktabs noobs compress label replace varlabel(ymean "Mean of Outcome") 
estimates drop _all
drop ymean


********************************************************************************
***** Table D.8 RD Specification - Controlling for Latitude and Longitude  *****
********************************************************************************

estimates drop _all
use "processed data\letter_AlsaceLorraine.dta",clear

gen cant_ID = ID_2*1000+ID_3

eststo: rdrobust r92_yf distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($coordinates $segment2) vce(cluster cant_ID) h(10) 
estadd local Obs = e(N_h_r) + e(N_h_l) 
eststo: rdrobust r92_yf distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($coordinates $segment2) vce(cluster cant_ID)
estadd local Obs = e(N_h_r) + e(N_h_l) 
eststo: rdrobust r05_yf distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($coordinates $segment2) vce(cluster cant_ID) h(10) 
estadd local Obs = e(N_h_r) + e(N_h_l) 
eststo: rdrobust r05_yf distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($coordinates $segment2)  vce(cluster cant_ID)  
estadd local Obs = e(N_h_r) + e(N_h_l)  

use "processed data\reshaped_letter_AlsaceLorraine.dta",clear

keep if year == 1992 | year == 2005

gen cant_ID = ID_2*1000+ID_3

eststo: rdrobust yes_share distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($coordinates $segment2) vce(cluster cant_ID) h(10) 
estadd local Obs = e(N_h_r) + e(N_h_l) 
eststo: rdrobust yes_share distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($coordinates $segment2) vce(cluster cant_ID)
estadd local Obs = e(N_h_r) + e(N_h_l) 
esttab using "..\Paper EU Identity\Tables\ID_Table_main_coordinates.tex", fragment booktabs nostar replace cells(b(star fmt(3) nostar) se(par(( )) abs fmt(3)) p(par({[ ]}) abs fmt(3))) ///
				mlabel(none) style(fixed) collabels(none) nolines nogaps nonumbers varlabel(RD_Estimate "Treatment vs. Control") ///
				stats(h_r Obs, fmt(3 0) label("Bandwidth (km)" "Observations")) noabbr 
				
use "processed data\letter_AlsaceLorraine.dta",clear
estimates drop _all

gen ymean = r92_yf

eststo: estpost sum ymean if treat_AL !=. & distance2 > -10 & distance2 < 10, meanonly
eststo: estpost sum ymean if treat_AL !=. & distance2 > -15.247   & distance2 <  15.247  , meanonly

replace ymean = r05_yf

eststo: estpost sum ymean if treat_AL !=. & distance2 > -10 & distance2 < 10, meanonly
eststo: estpost sum ymean if treat_AL !=. & distance2 > -12.282   & distance2 < 12.282 , meanonly

use "processed data\reshaped_letter_AlsaceLorraine.dta",clear
keep if year == 1992 | year == 2005

gen ymean = yes_share

eststo: estpost sum ymean if treat_AL !=. & distance2 > -10 & distance2 < 10, meanonly
eststo: estpost sum ymean if treat_AL !=. & distance2 > -13.961  & distance2 < 13.961  , meanonly
esttab using "..\Paper EU Identity\Tables\ID_Table_main_ymean_coordinates.tex", cells("mean(fmt(2))") nomtitles collabels(none) fragment postfoot(\hline) nolines nogaps nonumbers booktabs noobs compress label replace varlabel(ymean "Mean of Outcome") 
estimates drop _all
drop ymean

estimates drop _all

use "processed data\reshaped_letter_AlsaceLorraine.dta", clear
estimates drop _all
drop if insee_code == 1

keep if year == 1994 | year == 1999 | year == 2004

gen cant_ID = ID_2*1000+ID_3

eststo: rdrobust sum_EUvoteshare_neg distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($coordinates $segment2) vce(cluster cant_ID) h(10)
estadd local Obs = e(N_h_r) + e(N_h_l) 
eststo: rdrobust sum_EUvoteshare_neg distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($coordinates $segment2) vce(cluster cant_ID)
estadd local Obs = e(N_h_r) + e(N_h_l)
eststo: rdrobust sum_EUvoteshare_neg_noFN distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($coordinates $segment2) vce(cluster cant_ID) h(10)
estadd local Obs = e(N_h_r) + e(N_h_l) 
eststo: rdrobust sum_EUvoteshare_neg_noFN distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($coordinates $segment2) vce(cluster cant_ID)
estadd local Obs = e(N_h_r) + e(N_h_l)
eststo: rdrobust sum_weight_EUvoteshare_neg2_ distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($coordinates $segment2) vce(cluster cant_ID) h(10)
estadd local Obs = e(N_h_r) + e(N_h_l) 
eststo: rdrobust sum_weight_EUvoteshare_neg2_ distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($coordinates $segment2) vce(cluster cant_ID)
estadd local Obs = e(N_h_r) + e(N_h_l)   
esttab using "..\Paper EU Identity\Tables\ID_Table_eurosceptic_final_coordinates.tex", fragment booktabs nostar replace cells(b(star fmt(3) nostar) se(par(( )) abs fmt(3)) p(par({[ ]}) abs fmt(3)))  ///
				mlabel(none) style(fixed) collabels(none) nolines nogaps nonumbers varlabel(RD_Estimate "Treatment vs. Control") ///
				stats(h_r Obs, fmt(3 0) label("Bandwidth (km)" "Observations")) noabbr 

estimates drop _all

gen ymean = sum_EUvoteshare_neg

eststo: estpost sum ymean if treat_AL !=. & distance2 > -10 & distance2 < 10, meanonly
eststo: estpost sum ymean if treat_AL !=. & distance2 > -15.238    & distance2 <  15.238   , meanonly


replace ymean = sum_EUvoteshare_neg_noFN 

eststo: estpost sum ymean if treat_AL !=. & distance2 > -10 & distance2 < 10, meanonly
eststo: estpost sum ymean if treat_AL !=. & distance2 > -18.464     & distance2 < 18.464  , meanonly

replace ymean = sum_weight_EUvoteshare_neg2_

eststo: estpost sum ymean if treat_AL !=. & distance2 > -10 & distance2 < 10, meanonly
eststo: estpost sum ymean if treat_AL !=. & distance2 > -15.050      & distance2 < 15.050  , meanonly
esttab using "..\Paper EU Identity\Tables\ID_Table_main_eurosceptic_final_ymean_coordinates.tex", cells("mean(fmt(2))") nomtitles collabels(none) fragment postfoot(\hline) nolines nogaps nonumbers booktabs noobs compress label replace varlabel(ymean "Mean of Outcome") 
estimates drop _all
drop ymean


********************************************************************************
***** Table D.9 RD RD Specification - Baseline Plus Pre-Treatment Controls *****
********************************************************************************

estimates drop _all
use "processed data\letter_AlsaceLorraine.dta",clear

gen cant_ID = ID_2*1000+ID_3

eststo: rdrobust r92_yf distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2 $pretreatment) vce(cluster cant_ID) h(10) 
estadd local Obs = e(N_h_r) + e(N_h_l) 
eststo: rdrobust r92_yf distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2 $pretreatment) vce(cluster cant_ID)
estadd local Obs = e(N_h_r) + e(N_h_l) 
eststo: rdrobust r05_yf distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2 $pretreatment) vce(cluster cant_ID) h(10) 
estadd local Obs = e(N_h_r) + e(N_h_l) 
eststo: rdrobust r05_yf distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2 $pretreatment)  vce(cluster cant_ID) h(10) 
estadd local Obs = e(N_h_r) + e(N_h_l)  

use "processed data\reshaped_letter_AlsaceLorraine.dta",clear

keep if year == 1992 | year == 2005

gen cant_ID = ID_2*1000+ID_3

eststo: rdrobust yes_share distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2 $pretreatment) vce(cluster cant_ID) h(10) 
estadd local Obs = e(N_h_r) + e(N_h_l) 
eststo: rdrobust yes_share distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2 $pretreatment) vce(cluster cant_ID)
estadd local Obs = e(N_h_r) + e(N_h_l) 
esttab using "..\Paper EU Identity\Tables\ID_Table_main_pretreatment.tex", fragment booktabs nostar replace cells(b(star fmt(3) nostar) se(par(( )) abs fmt(3)) p(par({[ ]}) abs fmt(3)))  ///
				mlabel(none) style(fixed) collabels(none) nolines nogaps nonumbers varlabel(RD_Estimate "Treatment vs. Control") ///
				stats(h_r Obs, fmt(3 0) label("Bandwidth (km)" "Observations")) noabbr 
				
use "processed data\letter_AlsaceLorraine.dta",clear
estimates drop _all

gen ymean = r92_yf

eststo: estpost sum ymean if treat_AL !=. & distance2 > -10 & distance2 < 10, meanonly
eststo: estpost sum ymean if treat_AL !=. & distance2 > -10.188   & distance2 < 10.188  , meanonly

replace ymean = r05_yf

eststo: estpost sum ymean if treat_AL !=. & distance2 > -10 & distance2 < 10, meanonly
eststo: estpost sum ymean if treat_AL !=. & distance2 > -10   & distance2 < 10  , meanonly

use "processed data\reshaped_letter_AlsaceLorraine.dta",clear
keep if year == 1992 | year == 2005

gen ymean = yes_share

eststo: estpost sum ymean if treat_AL !=. & distance2 > -10 & distance2 < 10, meanonly
eststo: estpost sum ymean if treat_AL !=. & distance2 > -12.362   & distance2 < 12.362  , meanonly
esttab using "..\Paper EU Identity\Tables\ID_Table_main_ymean_pretreatment.tex", cells("mean(fmt(2))") nomtitles collabels(none) fragment postfoot(\hline) nolines nogaps nonumbers booktabs noobs compress label replace varlabel(ymean "Mean of Outcome") 
estimates drop _all
drop ymean

estimates drop _all

use "processed data\reshaped_letter_AlsaceLorraine.dta", clear
estimates drop _all
drop if insee_code == 1

keep if year == 1994 | year == 1999 | year == 2004

gen cant_ID = ID_2*1000+ID_3

eststo: rdrobust sum_EUvoteshare_neg distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2 $pretreatment) vce(cluster cant_ID) h(10)
estadd local Obs = e(N_h_r) + e(N_h_l) 
eststo: rdrobust sum_EUvoteshare_neg distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2 $pretreatment) vce(cluster cant_ID)
estadd local Obs = e(N_h_r) + e(N_h_l)
eststo: rdrobust sum_EUvoteshare_neg_noFN distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2 $pretreatment) vce(cluster cant_ID) h(10)
estadd local Obs = e(N_h_r) + e(N_h_l) 
eststo: rdrobust sum_EUvoteshare_neg_noFN distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2 $pretreatment) vce(cluster cant_ID)
estadd local Obs = e(N_h_r) + e(N_h_l)
eststo: rdrobust sum_weight_EUvoteshare_neg2_ distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2 $pretreatment) vce(cluster cant_ID) h(10)
estadd local Obs = e(N_h_r) + e(N_h_l) 
eststo: rdrobust sum_weight_EUvoteshare_neg2_ distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2 $pretreatment) vce(cluster cant_ID)
estadd local Obs = e(N_h_r) + e(N_h_l)   
esttab using "..\Paper EU Identity\Tables\ID_Table_eurosceptic_final_pretreatment.tex", fragment booktabs nostar replace cells(b(star fmt(3) nostar) se(par(( )) abs fmt(3)) p(par({[ ]}) abs fmt(3)))  ///
				mlabel(none) style(fixed) collabels(none) nolines nogaps nonumbers varlabel(RD_Estimate "Treatment vs. Control") ///
				stats(h_r Obs, fmt(3 0) label("Bandwidth (km)" "Observations")) noabbr 

estimates drop _all

gen ymean = sum_EUvoteshare_neg

eststo: estpost sum ymean if treat_AL !=. & distance2 > -10 & distance2 < 10, meanonly
eststo: estpost sum ymean if treat_AL !=. & distance2 > -19.995   & distance2 < 19.995  , meanonly


replace ymean = sum_EUvoteshare_neg_noFN 

eststo: estpost sum ymean if treat_AL !=. & distance2 > -10 & distance2 < 10, meanonly
eststo: estpost sum ymean if treat_AL !=. & distance2 > -18.893      & distance2 < 18.893   , meanonly

replace ymean = sum_weight_EUvoteshare_neg2_

eststo: estpost sum ymean if treat_AL !=. & distance2 > -10 & distance2 < 10, meanonly
eststo: estpost sum ymean if treat_AL !=. & distance2 > -12.821     & distance2 < 12.821  , meanonly
esttab using "..\Paper EU Identity\Tables\ID_Table_main_eurosceptic_final_ymean_pretreatment.tex", cells("mean(fmt(2))") nomtitles collabels(none) fragment postfoot(\hline) nolines nogaps nonumbers booktabs noobs compress label replace varlabel(ymean "Mean of Outcome") 
estimates drop _all
drop ymean


********************************************************************************
*******  Table D.10 RD Specification - Robustness to Linguistic Border  ********
********************************************************************************

use "processed data\reshaped_letter_AlsaceLorraine.dta", clear
estimates drop _all
drop if insee_code == 1

keep if year == 1992 | year == 2005 | year == 1994 | year == 1999 | year == 2004

gen cant_ID = ID_2*1000+ID_3

gen distance_robust_border2 = distance_robust_border/1000
replace distance_robust_border2 = distance_robust_border2*-1 if row_dum2 == 0

gen is_oldmoselle = FE_moselle
replace is_oldmoselle = 0 if FE_meurthe ==1
replace is_oldmoselle = . if FE_moselle != 1 & FE_meurthe !=1

gen distance_old_meu_mos = dist_old_border
replace distance_old_meu_mos = dist_old_border * -1 if is_oldmoselle == 0
replace distance_old_meu_mos = . if is_oldmoselle == .

gen distance_old_meu_mos2 = distance_old_meu_mos/1000

gen is_borderingAL = 0 if treat_AL == 0
replace is_borderingAL = 1 if ID_2 == 8 | ID_2 == 51 | ID_2 == 52 | ID_2 == 70 

gen distance_france = dist_AL_restFRA
replace distance_france = distance_france * -1 if is_borderingAL == 1
replace distance_france = . if is_borderingAL == .

gen distance_france2 = distance_france/1000


gen dist_limited = distance_limited
replace dist_limited = distance_limited*-1 if treat_AL == 0
gen dist_limited2 = dist_limited/1000

estimates drop _all
eststo: rdrobust yes_share distance2 if treat_AL !=. , rho(1) kernel(uni) masspoints(off) covs($distances) vce(cluster cant_ID) 
estadd local Obs = e(N_h_r) + e(N_h_l) 
eststo: rdrobust yes_share dist_limited2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances) vce(cluster cant_ID) 
estadd local Obs = e(N_h_r) + e(N_h_l) 
eststo: rdrobust sum_EUvoteshare_neg distance2 if treat_AL !=. , rho(1) kernel(uni) masspoints(off) covs($distances) vce(cluster cant_ID) 
estadd local Obs = e(N_h_r) + e(N_h_l) 
eststo: rdrobust sum_EUvoteshare_neg dist_limited2 if treat_AL !=. , rho(1) kernel(uni) masspoints(off) covs($distances) vce(cluster cant_ID)
estadd local Obs = e(N_h_r) + e(N_h_l)  
esttab using "..\Paper EU Identity\Tables\ID_Table_language_final.tex", fragment booktabs nostar replace cells(b(star fmt(3) nostar) se(par(( )) abs fmt(3)) p(par({[ ]}) abs fmt(3)))  ///
				mlabel(none) style(fixed) collabels(none) nolines nogaps nonumbers varlabel(RD_Estimate "Treatment vs. Control") ///
				stats(h_r Obs, fmt(3 0) label("Bandwidth (km)" "Observations")) noabbr 

estimates drop _all

gen ymean = yes_share

eststo: estpost sum ymean if treat_AL !=. & distance2 >  -14.529 & distance2 <  14.529, meanonly

eststo: estpost sum ymean if treat_AL !=. & dist_limited2 > -22.997   & dist_limited2 <  22.997  , meanonly

replace ymean = sum_EUvoteshare_neg

eststo: estpost sum ymean if treat_AL !=. & distance2 > -16.179    & distance2 <  16.179    , meanonly

eststo: estpost sum ymean if treat_AL !=. & dist_limited2 >  -22.430   & dist_limited2 < 22.430    , meanonly
esttab using "..\Paper EU Identity\Tables\ID_Table_language_final_ymean.tex", cells("mean(fmt(2))") nomtitles collabels(none) fragment postfoot(\hline) nolines nogaps nonumbers booktabs noobs compress label replace varlabel(ymean "Mean of Outcome") 
estimates drop _all
drop ymean

*****************************************************************************************************************************************************
***  Figure D.1 RD Specification - Robustness: Modified Border - Francophone Municipalities Only and Controlling for Distance to Language Border  ***
*****************************************************************************************************************************************************

use "processed data\reshaped_letter_AlsaceLorraine.dta",clear
gen cant_ID = ID_2*1000+ID_3
keep if year == 1992 |year == 2005 | year == 1994 | year == 1999 | year == 2004

gen dist_limited = distance_limited
replace dist_limited = distance_limited*-1 if treat_AL == 0
gen dist_limited2 = dist_limited/1000

estimates drop _all

mat B=J(4,2,0)

local no = 1
rdrobust yes_share dist_limited2 if treat_AL !=. & francophone==1, rho(1) kernel(uni) masspoints(off) covs($distances) vce(cluster cant_ID) h(22.997 )
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix B[`no', 1] =  b`no'
matrix B[`no', 2] =  s`no'
local no = `no'+1
rdrobust yes_share dist_limited2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances dist_language2) vce(cluster cant_ID) h(22.997 )
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix B[`no', 1] =  b`no'
matrix B[`no', 2] =  s`no'
local no = `no'+1
rdrobust sum_EUvoteshare_neg dist_limited2 if treat_AL !=. & francophone==1, rho(1) kernel(uni) masspoints(off) covs($distances) vce(cluster cant_ID) h(22.430)
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix B[`no', 1] =  b`no'
matrix B[`no', 2] =  s`no'
local no = `no'+1
rdrobust sum_EUvoteshare_neg dist_limited2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances dist_language2) vce(cluster cant_ID) h(22.430)
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix B[`no', 1] =  b`no'
matrix B[`no', 2] =  s`no'
coefplot matrix(B[,1]), se(B[,2]) xline(0, lcolor(black)) msize(medium) xlabel(-2 0 2 4 6) xscale(range(-4 8))  /// 
coeflabels(r1 = "Francophone municipalities only" r2 = "Control for language border" ///
 r3 = "Francophone municipalities only" r4 = "Control for language border", labsize(medium)) ///
 levels(90) ciopts(lcolor(black) lstyle(p15)) graphregion(color(white)) xlabel( -2 0 2 4 6, nogrid) ///
 headings(r1 = "{bf:EU Support}" r3 = "{bf:Euroscepticism}", labsize(medlarge))

graph export "..\Paper EU Identity\Graphs\coefplot_francophone_Yes_eurosceptic.png", replace width(3000) height(2000)
graph export "..\Paper EU Identity\Graphs\coefplot_francophone_Yes_eurosceptic.pdf", replace

estimates drop _all


*******************************************************************************************************************
***  Figure D.2 Robustness - Modified Border Excluding Overlaps with Linguistic Border, All Outcomes Displayed  ***
*******************************************************************************************************************

use "processed data\reshaped_letter_AlsaceLorraine.dta", clear
estimates drop _all
drop if insee_code == 1

keep if year == 1992 | year == 2005 | year == 1994 | year == 1999 | year == 2004

gen cant_ID = ID_2*1000+ID_3

gen distance_robust_border2 = distance_robust_border/1000
replace distance_robust_border2 = distance_robust_border2*-1 if row_dum2 == 0

gen is_oldmoselle = FE_moselle
replace is_oldmoselle = 0 if FE_meurthe ==1
replace is_oldmoselle = . if FE_moselle != 1 & FE_meurthe !=1

gen distance_old_meu_mos = dist_old_border
replace distance_old_meu_mos = dist_old_border * -1 if is_oldmoselle == 0
replace distance_old_meu_mos = . if is_oldmoselle == .

gen distance_old_meu_mos2 = distance_old_meu_mos/1000

gen is_borderingAL = 0 if treat_AL == 0
replace is_borderingAL = 1 if ID_2 == 8 | ID_2 == 51 | ID_2 == 52 | ID_2 == 70 

gen distance_france = dist_AL_restFRA
replace distance_france = distance_france * -1 if is_borderingAL == 1
replace distance_france = . if is_borderingAL == .

gen distance_france2 = distance_france/1000


gen dist_limited = distance_limited
replace dist_limited = distance_limited*-1 if treat_AL == 0
gen dist_limited2 = dist_limited/1000


******************************************
*** Split by year for reviewer comment ***
******************************************

mat C=J(12,2,0)

local no = 1
rdrobust yes_share distance2 if treat_AL !=. , rho(1) kernel(uni) masspoints(off) covs($distances) vce(cluster cant_ID) 
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix C[`no', 1] =  b`no'
matrix C[`no', 2] =  s`no'
local no = `no'+1

rdrobust yes_share dist_limited2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances) vce(cluster cant_ID) 
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix C[`no', 1] =  b`no'
matrix C[`no', 2] =  s`no'
local no = `no'+1

rdrobust r92_yf distance2 if treat_AL !=. , rho(1) kernel(uni) masspoints(off) covs($distances) vce(cluster cant_ID) 
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix C[`no', 1] =  b`no'
matrix C[`no', 2] =  s`no'
local no = `no'+1

rdrobust r92_yf dist_limited2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances) vce(cluster cant_ID) 
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix C[`no', 1] =  b`no'
matrix C[`no', 2] =  s`no'
local no = `no'+1

rdrobust r05_yf distance2 if treat_AL !=. , rho(1) kernel(uni) masspoints(off) covs($distances) vce(cluster cant_ID) 
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix C[`no', 1] =  b`no'
matrix C[`no', 2] =  s`no'
local no = `no'+1

rdrobust r05_yf dist_limited2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances) vce(cluster cant_ID) 
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix C[`no', 1] =  b`no'
matrix C[`no', 2] =  s`no'
local no = `no'+1

rdrobust sum_EUvoteshare_neg distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances) vce(cluster cant_ID) 
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix C[`no', 1] =  b`no'
matrix C[`no', 2] =  s`no'
local no = `no'+1

rdrobust sum_EUvoteshare_neg dist_limited2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances) vce(cluster cant_ID) 
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix C[`no', 1] =  b`no'
matrix C[`no', 2] =  s`no'
local no = `no'+1

rdrobust sum_EUvoteshare_neg_noFN distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances) vce(cluster cant_ID) 
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix C[`no', 1] =  b`no'
matrix C[`no', 2] =  s`no'
local no = `no'+1

rdrobust sum_EUvoteshare_neg_noFN dist_limited2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances) vce(cluster cant_ID) 
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix C[`no', 1] =  b`no'
matrix C[`no', 2] =  s`no'
local no = `no'+1

rdrobust sum_weight_EUvoteshare_neg2_ distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances) vce(cluster cant_ID) 
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix C[`no', 1] =  b`no'
matrix C[`no', 2] =  s`no'
local no = `no'+1

rdrobust sum_weight_EUvoteshare_neg2_ dist_limited2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances) vce(cluster cant_ID) 
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix C[`no', 1] =  b`no'
matrix C[`no', 2] =  s`no'
local no = `no'+1

coefplot matrix(C[,1]), se(C[,2]) xline(0, lcolor(black)) msize(medium) xlabel(-2 0 2 4 6) xscale(range(-4 8))  /// 
coeflabels(r1 = "Baseline (1992 & 2005)" r2 = "Modified (1992 & 2005)" r3 = "Baseline (1992)" r4 = "Modified (1992)" r5 = "Baseline (2005)"  r6 = "Modified (2005)" r7 = "Baseline (Eurosceptic Parties)" r8 = "Modified (Eurosceptic Parties)" r9 = "Baseline (w/o Front National)" r10 = "Modified (w/o Front National)" r11 = "Baseline (Euroscepticism Index)" r12 = "Modified (Euroscepticism Index)", labsize(medium)) levels(90) ciopts(lcolor(black) lstyle(p15)) graphregion(color(white)) headings(r1 = "{bf:EU Support}" r7 = "{bf:Euroscepticism}", labsize(medlarge)) xlabel( -2 0 2 4 6, nogrid)

graph export "..\Paper EU Identity\Graphs\coefplot_treatborderlimited_split.tif", replace width(3000) height(2000)
graph export "..\Paper EU Identity\Graphs\coefplot_treatborderlimited_split.png", replace width(3000) height(2000)
graph export "..\Paper EU Identity\Graphs\coefplot_treatborderlimited_split.pdf", replace
estimates drop _all


********************************************************************************
*************  Figure D.3 Robustness Check - Bandwidth Choice  *****************
********************************************************************************

use "processed data\letter_AlsaceLorraine.dta", clear
gen cant_ID = ID_2*1000+ID_3


mat B=J(11,2,0)

local no = 1
local BW = 10
quietly: rdrobust r92_yf distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) vce(cluster cant_ID) h(`BW') 
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix B[`no', 1] =  b`no'
matrix B[`no', 2] =  s`no'
local no = `no'+1
local BW = `BW'+2.5
quietly: rdrobust r92_yf distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) vce(cluster cant_ID) h(13.419) 
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix B[`no', 1] =  b`no'
matrix B[`no', 2] =  s`no'
local no = `no'+1
local BW = `BW'+2.5
quietly: rdrobust r92_yf distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) vce(cluster cant_ID) h(`BW') 
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix B[`no', 1] =  b`no'
matrix B[`no', 2] =  s`no'
local no = `no'+1
local BW = `BW'+2.5
quietly: rdrobust r92_yf distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) vce(cluster cant_ID) h(`BW') 
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix B[`no', 1] =  b`no'
matrix B[`no', 2] =  s`no'
local no = `no'+1
local BW = `BW'+2.5
quietly: rdrobust r92_yf distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) vce(cluster cant_ID) h(`BW') 
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix B[`no', 1] =  b`no'
matrix B[`no', 2] =  s`no'
local no = `no'+1
local BW = `BW'+2.5
quietly: rdrobust r92_yf distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) vce(cluster cant_ID) h(`BW') 
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix B[`no', 1] =  b`no'
matrix B[`no', 2] =  s`no'
local no = `no'+1
local BW = `BW'+2.5
quietly: rdrobust r92_yf distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) vce(cluster cant_ID) h(`BW') 
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix B[`no', 1] =  b`no'
matrix B[`no', 2] =  s`no'
local no = `no'+1
local BW = `BW'+2.5
quietly: rdrobust r92_yf distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) vce(cluster cant_ID) h(`BW') 
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix B[`no', 1] =  b`no'
matrix B[`no', 2] =  s`no'
local no = `no'+1
local BW = `BW'+2.5
quietly: rdrobust r92_yf distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) vce(cluster cant_ID) h(`BW') 
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix B[`no', 1] =  b`no'
matrix B[`no', 2] =  s`no'
local no = `no'+1
local BW = `BW'+2.5
quietly: rdrobust r92_yf distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) vce(cluster cant_ID) h(`BW') 
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix B[`no', 1] =  b`no'
matrix B[`no', 2] =  s`no'
local no = `no'+1
local BW = `BW'+2.5
quietly: rdrobust r92_yf distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) vce(cluster cant_ID) h(`BW') 
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix B[`no', 1] =  b`no'
matrix B[`no', 2] =  s`no'
coefplot matrix(B[,1]), se(B[,2]) yline(0, lcolor(black)) msize(medium)  coeflabels(r1 = "10" r2 = "Eff. BW" r3 = "15" r4 = "17.5" r5 = "20" r6 = "22.5" r7 = "25" r8="27.5" r9="30" r10="32.5" r11="35", grid) xtitle("Bandwidth in km" , color(black) margin(medium)) levels(90) ciopts(lcolor(black) lstyle(p15)) graphregion(color(white)) ylabel(-5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 8 9, nogrid) vertical ytitle("Coefficient") // xlabel(1 2 3 4 5 6 7 8 "Eff. BW" 9 10 11)

graph export "..\Paper EU Identity\Graphs\coefplot_Yes92_BW_robust.png", replace width(3000) height(2000)
graph export "..\Paper EU Identity\Graphs\coefplot_Yes92_BW_robust.tif", replace width(3000) height(2000)


mat B=J(7,2,0)


local no = 1
local BW = 10
quietly: rdrobust r05_yf distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) vce(cluster cant_ID) h(`BW')  
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix B[`no', 1] =  b`no'
matrix B[`no', 2] =  s`no'
local no = `no'+1
local BW = `BW'+2.5
quietly: rdrobust r05_yf distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) vce(cluster cant_ID) h(`BW') 
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix B[`no', 1] =  b`no'
matrix B[`no', 2] =  s`no'
local no = `no'+1
local BW = `BW'+2.5
quietly: rdrobust r05_yf distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) vce(cluster cant_ID) h(`BW') 
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix B[`no', 1] =  b`no'
matrix B[`no', 2] =  s`no'
local no = `no'+1
local BW = `BW'+2.5
quietly: rdrobust r05_yf distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) vce(cluster cant_ID) h(`BW') 
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix B[`no', 1] =  b`no'
matrix B[`no', 2] =  s`no'
local no = `no'+1
local BW = `BW'+2.5
quietly: rdrobust r05_yf distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) vce(cluster cant_ID) h(`BW') 
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix B[`no', 1] =  b`no'
matrix B[`no', 2] =  s`no'
local no = `no'+1
local BW = `BW'+2.5
quietly: rdrobust r05_yf distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) vce(cluster cant_ID) h(`BW') 
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix B[`no', 1] =  b`no'
matrix B[`no', 2] =  s`no'
local no = `no'+1
local BW = `BW'+2.5
quietly: rdrobust r05_yf distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) vce(cluster cant_ID) h(`BW') 
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix B[`no', 1] =  b`no'
matrix B[`no', 2] =  s`no'
coefplot matrix(B[,1]), se(B[,2]) yline(0, lcolor(black)) msize(medium)  coeflabels(r1 = "Eff. BW" r2 = "12.5" r3 = "15" r4 = "17.5" r5 = "20" r6 = "22.5" r7 = "25", grid) xtitle("Bandwidth in km" , color(black) margin(medium)) levels(90) ciopts(lcolor(black) lstyle(p15)) graphregion(color(white)) ylabel(-5 -4 -3 -2 -1  0 1 2 3 4 5 6 7 8 9, nogrid) vertical ytitle("Coefficient") //xlabel(1 2 3 "Eff. BW" 4 5 6)

graph export "..\Paper EU Identity\Graphs\coefplot_Yes05_BW_robust.png", replace width(3000) height(2000)
graph export "..\Paper EU Identity\Graphs\coefplot_Yes05_BW_robust.tif", replace width(3000) height(2000)


use "processed data\reshaped_letter_AlsaceLorraine.dta", clear
estimates drop _all
drop if insee_code == 1

keep if year == 1992 | year == 2005 

gen cant_ID = ID_2*1000+ID_3

mat B=J(7,2,0)

local no = 1
local BW = 10
quietly: rdrobust yes_share distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) vce(cluster cant_ID) h(`BW') 
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix B[`no', 1] =  b`no'
matrix B[`no', 2] =  s`no'
local no = `no'+1
local BW = `BW'+2.5
rdrobust yes_share distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) vce(cluster cant_ID) h(12.530)
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix B[`no', 1] =  b`no'
matrix B[`no', 2] =  s`no'
local no = `no'+1
local BW = `BW'+2.5
rdrobust yes_share distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) vce(cluster cant_ID) h(`BW') 
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix B[`no', 1] =  b`no'
matrix B[`no', 2] =  s`no'
local no = `no'+1
local BW = `BW'+2.5
quietly: rdrobust yes_share distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) vce(cluster cant_ID) h(`BW') 
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix B[`no', 1] =  b`no'
matrix B[`no', 2] =  s`no'
local no = `no'+1
local BW = `BW'+2.5
quietly: rdrobust yes_share distance2 if treat_AL !=., rho(1) masspoints(off) covs($distances $segment2) vce(cluster cant_ID) h(`BW') 
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix B[`no', 1] =  b`no'
matrix B[`no', 2] =  s`no'
local no = `no'+1
local BW = `BW'+2.5
quietly: rdrobust yes_share distance2 if treat_AL !=., rho(1) masspoints(off) covs($distances $segment2) vce(cluster cant_ID) h(`BW') 
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix B[`no', 1] =  b`no'
matrix B[`no', 2] =  s`no'
local no = `no'+1
local BW = `BW'+2.5
quietly: rdrobust yes_share distance2 if treat_AL !=., rho(1) masspoints(off) covs($distances $segment2) vce(cluster cant_ID) h(`BW') 
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix B[`no', 1] =  b`no'
matrix B[`no', 2] =  s`no'
coefplot matrix(B[,1]), se(B[,2]) yline(0, lcolor(black)) msize(medium)  coeflabels(r1 = "10" r2 = "Eff. BW" r3 = "15" r4 = "17.5" r5 = "20" r6 = "22.5" r7 = "25", grid) xtitle("Bandwidth in km" , color(black) margin(medium)) levels(90) ciopts(lcolor(black) lstyle(p15)) graphregion(color(white)) ylabel(-5 -4 -3 -2 -1  0 1 2 3 4 5 6 7 8 9, nogrid) vertical ytitle("Coefficient") // xlabel(1 2 3 "Eff. BW" 4 5 6)

graph export "..\Paper EU Identity\Graphs\coefplot_Yes9205_BW_robust.png", replace width(3000) height(2000)
graph export "..\Paper EU Identity\Graphs\coefplot_Yes9205_BW_robust.tif", replace width(3000) height(2000)


use "processed data\reshaped_letter_AlsaceLorraine.dta", clear
estimates drop _all
drop if insee_code == 1

keep if year == 1994 | year == 1999 | year == 2004

gen cant_ID = ID_2*1000+ID_3

mat B=J(7,2,0)

local no = 1
local BW = 10
quietly: rdrobust sum_EUvoteshare_neg distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) vce(cluster cant_ID) h(`BW') 
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix B[`no', 1] =  b`no'
matrix B[`no', 2] =  s`no'
local no = `no'+1
local BW = `BW'+2.5
rdrobust sum_EUvoteshare_neg distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) vce(cluster cant_ID) h(`BW') 
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix B[`no', 1] =  b`no'
matrix B[`no', 2] =  s`no'
local no = `no'+1
local BW = `BW'+2.5
rdrobust sum_EUvoteshare_neg distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) vce(cluster cant_ID) h(14.369) 
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix B[`no', 1] =  b`no'
matrix B[`no', 2] =  s`no'
local no = `no'+1
local BW = `BW'+2.5
quietly: rdrobust sum_EUvoteshare_neg distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) vce(cluster cant_ID) h(`BW') 
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix B[`no', 1] =  b`no'
matrix B[`no', 2] =  s`no'
local no = `no'+1
local BW = `BW'+2.5
quietly: rdrobust sum_EUvoteshare_neg distance2 if treat_AL !=., rho(1) masspoints(off) covs($distances $segment2) vce(cluster cant_ID) h(`BW') 
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix B[`no', 1] =  b`no'
matrix B[`no', 2] =  s`no'
local no = `no'+1
local BW = `BW'+2.5
quietly: rdrobust sum_EUvoteshare_neg distance2 if treat_AL !=., rho(1) masspoints(off) covs($distances $segment2) vce(cluster cant_ID) h(`BW') 
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix B[`no', 1] =  b`no'
matrix B[`no', 2] =  s`no'
local no = `no'+1
local BW = `BW'+2.5
quietly: rdrobust sum_EUvoteshare_neg distance2 if treat_AL !=., rho(1) masspoints(off) covs($distances $segment2) vce(cluster cant_ID) h(`BW') 
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix B[`no', 1] =  b`no'
matrix B[`no', 2] =  s`no'
coefplot matrix(B[,1]), se(B[,2]) yline(0, lcolor(black)) msize(medium)  coeflabels(r1 = "10" r2 = "12.5" r3 = "Eff. BW" r4 = "17.5" r5 = "20" r6 = "22.5" r7 = "25", grid) xtitle("Bandwidth in km" , color(black) margin(medium)) levels(90) ciopts(lcolor(black) lstyle(p15)) graphregion(color(white)) ylabel(-5 -4 -3 -2 -1  0 1 2, nogrid) vertical ytitle("Coefficient") // xlabel(1 2 3 "Eff. BW" 4 5 6)

graph export "..\Paper EU Identity\Graphs\coefplot_Euroscept1_BW_robust.png", replace width(3000) height(2000)
graph export "..\Paper EU Identity\Graphs\coefplot_Euroscept1_BW_robust.tif", replace width(3000) height(2000)


mat B=J(7,2,0)

local no = 1
local BW = 10
quietly: rdrobust sum_EUvoteshare_neg_noFN distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) vce(cluster cant_ID) h(`BW') 
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix B[`no', 1] =  b`no'
matrix B[`no', 2] =  s`no'
local no = `no'+1
local BW = `BW'+2.5
rdrobust sum_EUvoteshare_neg_noFN distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) vce(cluster cant_ID) h(`BW') 
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix B[`no', 1] =  b`no'
matrix B[`no', 2] =  s`no'
local no = `no'+1
local BW = `BW'+2.5
rdrobust sum_EUvoteshare_neg_noFN distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) vce(cluster cant_ID) h(`BW') 
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix B[`no', 1] =  b`no'
matrix B[`no', 2] =  s`no'
local no = `no'+1
local BW = `BW'+2.5
quietly: rdrobust sum_EUvoteshare_neg_noFN distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) vce(cluster cant_ID) h(17.819 ) 
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix B[`no', 1] =  b`no'
matrix B[`no', 2] =  s`no'
local no = `no'+1
local BW = `BW'+2.5
quietly: rdrobust sum_EUvoteshare_neg_noFN distance2 if treat_AL !=., rho(1) masspoints(off) covs($distances $segment2) vce(cluster cant_ID) h(`BW') 
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix B[`no', 1] =  b`no'
matrix B[`no', 2] =  s`no'
local no = `no'+1
local BW = `BW'+2.5
quietly: rdrobust sum_EUvoteshare_neg_noFN distance2 if treat_AL !=., rho(1) masspoints(off) covs($distances $segment2) vce(cluster cant_ID) h(`BW') 
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix B[`no', 1] =  b`no'
matrix B[`no', 2] =  s`no'
local no = `no'+1
local BW = `BW'+2.5
quietly: rdrobust sum_EUvoteshare_neg_noFN distance2 if treat_AL !=., rho(1) masspoints(off) covs($distances $segment2) vce(cluster cant_ID) h(`BW') 
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix B[`no', 1] =  b`no'
matrix B[`no', 2] =  s`no'
coefplot matrix(B[,1]), se(B[,2]) yline(0, lcolor(black)) msize(medium)  coeflabels(r1 = "10" r2 = "12.5" r3 = "15" r4 = "Eff. BW" r5 = "20" r6 = "22.5" r7 = "25", grid) xtitle("Bandwidth in km" , color(black) margin(medium)) levels(90) ciopts(lcolor(black) lstyle(p15)) graphregion(color(white)) ylabel(-5 -4 -3 -2 -1  0 1 2, nogrid) vertical ytitle("Coefficient") // xlabel(1 2 3 "Eff. BW" 4 5 6)

graph export "..\Paper EU Identity\Graphs\coefplot_Euroscept2_BW_robust.png", replace width(3000) height(2000)
graph export "..\Paper EU Identity\Graphs\coefplot_Euroscept2_BW_robust.tif", replace width(3000) height(2000)


mat B=J(7,2,0)

local no = 1
local BW = 10
quietly: rdrobust sum_weight_EUvoteshare_neg2_ distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) vce(cluster cant_ID) h(`BW') 
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix B[`no', 1] =  b`no'
matrix B[`no', 2] =  s`no'
local no = `no'+1
local BW = `BW'+2.5
rdrobust sum_weight_EUvoteshare_neg2_ distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) vce(cluster cant_ID) h(`BW') 
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix B[`no', 1] =  b`no'
matrix B[`no', 2] =  s`no'
local no = `no'+1
local BW = `BW'+2.5
rdrobust sum_weight_EUvoteshare_neg2_ distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) vce(cluster cant_ID) h(`BW') 
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix B[`no', 1] =  b`no'
matrix B[`no', 2] =  s`no'
local no = `no'+1
local BW = `BW'+2.5
rdrobust sum_weight_EUvoteshare_neg2_ distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) vce(cluster cant_ID) h(16.675)
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix B[`no', 1] =  b`no'
matrix B[`no', 2] =  s`no'
local no = `no'+1
local BW = `BW'+2.5
quietly: rdrobust sum_weight_EUvoteshare_neg2_ distance2 if treat_AL !=., rho(1) masspoints(off) covs($distances $segment2) vce(cluster cant_ID) h(`BW') 
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix B[`no', 1] =  b`no'
matrix B[`no', 2] =  s`no'
local no = `no'+1
local BW = `BW'+2.5
quietly: rdrobust sum_weight_EUvoteshare_neg2_ distance2 if treat_AL !=., rho(1) masspoints(off) covs($distances $segment2) vce(cluster cant_ID) h(`BW') 
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix B[`no', 1] =  b`no'
matrix B[`no', 2] =  s`no'
local no = `no'+1
local BW = `BW'+2.5
quietly: rdrobust sum_weight_EUvoteshare_neg2_ distance2 if treat_AL !=., rho(1) masspoints(off) covs($distances $segment2) vce(cluster cant_ID) h(`BW') 
scalar b`no' = e(tau_cl)
scalar s`no' = e(se_tau_cl)
matrix B[`no', 1] =  b`no'
matrix B[`no', 2] =  s`no'
coefplot matrix(B[,1]), se(B[,2]) yline(0, lcolor(black)) msize(medium)  coeflabels(r1 = "10" r2 = "12.5" r3 = "15" r4 = "Eff. BW" r5 = "20" r6 = "22.5" r7 = "25", grid) xtitle("Bandwidth in km" , color(black) margin(medium)) levels(90) ciopts(lcolor(black) lstyle(p15)) graphregion(color(white)) ylabel(-9 -8 -7 -6 -5 -4 -3 -2 -1  0 1 2, nogrid) vertical ytitle("Coefficient") // xlabel(1 2 3 "Eff. BW" 4 5 6)

graph export "..\Paper EU Identity\Graphs\coefplot_Euroscept3_BW_robust.png", replace width(3000) height(2000)
graph export "..\Paper EU Identity\Graphs\coefplot_Euroscept3_BW_robust.tif", replace width(3000) height(2000)


*************************************************************************************************
*************  Table D.11 RD Results EU Support (1992 - 2005) - Full Results Table **************
*************************************************************************************************

estimates drop _all
use "processed data\letter_AlsaceLorraine.dta",clear

gen cant_ID = ID_2*1000+ID_3

eststo: reg r92_yf i.treat_AL##c.distance2 $distances $segment2 if treat_AL !=. & distance2 > -10 & distance2 < 10, cluster(cant_ID) r
estadd scalar h_r = 10.000
eststo: reg r92_yf i.treat_AL##c.distance2 $distances $segment2 if treat_AL !=. & distance2 > -13.419 & distance2 < 13.419, cluster(cant_ID)  r
estadd scalar h_r = 13.419 
eststo: reg r05_yf i.treat_AL##c.distance2 $distances $segment2 if treat_AL !=. & distance2 > -10 & distance2 < 10, cluster(cant_ID) r
estadd scalar h_r = 10.000
eststo: reg r05_yf i.treat_AL##c.distance2 $distances $segment2 if treat_AL !=. & distance2 > -10 & distance2 < 10, cluster(cant_ID) r
estadd scalar h_r = 10.000

use "processed data\reshaped_letter_AlsaceLorraine.dta",clear

keep if year == 1992 | year == 2005

gen cant_ID = ID_2*1000+ID_3

eststo: reg yes_share i.treat_AL##c.distance2 $distances $segment2 if treat_AL !=. & distance2 > -10 & distance2 < 10, cluster(cant_ID)  r
estadd scalar h_r = 10.000
eststo: reg yes_share i.treat_AL##c.distance2 $distances $segment2 if treat_AL !=. & distance2 > -12.530 & distance2 < 12.530, cluster(cant_ID) r
estadd scalar h_r = 12.530
esttab using "..\Paper EU Identity\Tables\ID_Table_main_full.tex", fragment booktabs nostar replace cells(b(star fmt(3) nostar) se(par(( )) abs fmt(3)) p(par({[ ]}) abs fmt(3)))  ///
				mlabel(none) style(fixed) collabels(none) nolines nogaps nonumbers varlabel(1.treat_AL "Treatment vs. Control" dist_b_ASLR_DEU "Distance to Germany" dist_c_METZ "Distance to Metz" dist_c_STRASBOURG "Distance to Strasbourg" dist_c_NANCY "Distance to Nancy" dist_mulhouse "Distance to Mulhouse" AL_seg1 "Border Segment 1" AL_seg2 "Border Segment 2" AL_seg3 "Border Segment 3" AL_seg4 "Border Segment 4") keep(1.treat_AL $distances $segment2) ///
				stats(h_r N, fmt(3 0) label("Bandwidth (km)" "Observations")) noabbr 
				
estimates drop _all


******************************************************************************************************
*************  Table D.12 RD Results Euroscepticism (1992 - 2005) - Full Results Table  **************
******************************************************************************************************

estimates drop _all

use "processed data\reshaped_letter_AlsaceLorraine.dta", clear
estimates drop _all
drop if insee_code == 1

keep if year == 1994 | year == 1999 | year == 2004

gen cant_ID = ID_2*1000+ID_3

eststo: reg sum_EUvoteshare_neg c.distance2##i.treat_AL $distances $segment2 if treat_AL !=. & distance2 > -10 & distance2 < 10 , cluster(cant_ID) r
estadd scalar h_r = 10.000
eststo: reg sum_EUvoteshare_neg c.distance2##i.treat_AL $distances $segment2 if treat_AL !=. & distance2 > -14.369 & distance2 < 14.369 , cluster(cant_ID) r
estadd scalar h_r = 14.369
eststo: reg sum_EUvoteshare_neg_noFN c.distance2##i.treat_AL $distances $segment2 if treat_AL !=. & distance2 > -10 & distance2 < 10 , cluster(cant_ID) r
estadd scalar h_r = 10.000
eststo: reg sum_EUvoteshare_neg_noFN c.distance2##i.treat_AL $distances $segment2 if treat_AL !=. & distance2 > -17.819  & distance2 < 17.819  , cluster(cant_ID) r
estadd scalar h_r = 17.819 
eststo: reg sum_weight_EUvoteshare_neg2_ c.distance2##i.treat_AL $distances $segment2 if treat_AL !=. & distance2 > -10 & distance2 < 10 , cluster(cant_ID) r
estadd scalar h_r = 10.000
eststo: reg sum_weight_EUvoteshare_neg2_ c.distance2##i.treat_AL $distances $segment2 if treat_AL !=. & distance2 > -16.675 & distance2 < 16.675 , cluster(cant_ID) r
estadd scalar h_r = 16.675 
esttab using "..\Paper EU Identity\Tables\ID_Table_eurosceptic_final_full.tex", fragment booktabs nostar replace cells(b(star fmt(3) nostar) se(par(( )) abs fmt(3)) p(par({[ ]}) abs fmt(3)))  ///
				mlabel(none) style(fixed) collabels(none) nolines nogaps nonumbers varlabel(1.treat_AL "Treatment vs. Control" dist_b_ASLR_DEU "Distance to Germany" dist_c_METZ "Distance to Metz" dist_c_STRASBOURG "Distance to Strasbourg" dist_c_NANCY "Distance to Nancy" dist_mulhouse "Distance to Mulhouse" AL_seg1 "Border Segment 1" AL_seg2 "Border Segment 2" AL_seg3 "Border Segment 3" AL_seg4 "Border Segment 4") keep(1.treat_AL $distances $segment2)  ///
				stats(h_r N, fmt(3 0) label("Bandwidth (km)" "Observations")) noabbr 

estimates drop _all


********************************************************************************
*************  Table D.13 RD Specification - Placebo Borders  ******************
********************************************************************************

use "processed data\reshaped_letter_AlsaceLorraine.dta", clear
estimates drop _all
drop if insee_code == 1

keep if year == 1992 | year == 2005 | year == 1994 | year == 1999 | year == 2004

gen cant_ID = ID_2*1000+ID_3

gen distance_robust_border2 = distance_robust_border/1000
replace distance_robust_border2 = distance_robust_border2*-1 if row_dum2 == 0

gen is_oldmoselle = FE_moselle
replace is_oldmoselle = 0 if FE_meurthe ==1
replace is_oldmoselle = . if FE_moselle != 1 & FE_meurthe !=1

gen distance_old_meu_mos = dist_old_border
replace distance_old_meu_mos = dist_old_border * -1 if is_oldmoselle == 0
replace distance_old_meu_mos = . if is_oldmoselle == .

gen distance_old_meu_mos2 = distance_old_meu_mos/1000

gen is_borderingAL = 0 if treat_AL == 0
replace is_borderingAL = 1 if ID_2 == 8 | ID_2 == 51 | ID_2 == 52 | ID_2 == 70 

gen distance_france = dist_AL_restFRA
replace distance_france = distance_france * -1 if is_borderingAL == 1
replace distance_france = . if is_borderingAL == .

gen distance_france2 = distance_france/1000


gen dist_limited = distance_limited
replace dist_limited = distance_limited*-1 if treat_AL == 0
gen dist_limited2 = dist_limited/1000


eststo: rdrobust yes_share distance_robust_border2 if treat_AL ==. & row_dum2 !=., rho(1) kernel(uni) masspoints(off) covs($distances) vce(cluster cant_ID)  
estadd local Obs = e(N_h_r) + e(N_h_l) 
eststo: rdrobust sum_EUvoteshare_neg distance_robust_border2 if treat_AL ==. & row_dum2 !=., rho(1) kernel(uni) masspoints(off) covs($distances) vce(cluster cant_ID) 
estadd local Obs = e(N_h_r) + e(N_h_l) 
eststo: rdrobust yes_share distance_old_meu_mos2  if is_oldmoselle !=., rho(1) kernel(uni) masspoints(off) covs($distances) vce(cluster cant_ID)  h(10)
estadd local Obs = e(N_h_r) + e(N_h_l) 
eststo: rdrobust sum_EUvoteshare_neg distance_old_meu_mos2 if is_oldmoselle !=., rho(1) kernel(uni) masspoints(off) covs($distances) vce(cluster cant_ID) h(10)
estadd local Obs = e(N_h_r) + e(N_h_l) 
eststo: rdrobust yes_share distance_france2 if is_borderingAL !=., rho(1) kernel(uni) masspoints(off) covs($distances) vce(cluster cant_ID) 
estadd local Obs = e(N_h_r) + e(N_h_l) 
eststo: rdrobust sum_EUvoteshare_neg distance_france2 if is_borderingAL !=., rho(1) kernel(uni) masspoints(off) covs($distances) vce(cluster cant_ID) 
estadd local Obs = e(N_h_r) + e(N_h_l)   
esttab using "..\Paper EU Identity\Tables\ID_Table_placebo_final.tex", fragment booktabs nostar replace cells(b(star fmt(3) nostar) se(par(( )) abs fmt(3)) p(par({[ ]}) abs fmt(3)))  ///
				mlabel(none) style(fixed) collabels(none) nolines nogaps nonumbers varlabel(RD_Estimate "Treatment vs. Control") ///
				stats(h_r Obs, fmt(3 0) label("Bandwidth (km)" "Observations")) noabbr 

estimates drop _all

gen ymean = yes_share

eststo: estpost sum ymean if treat_AL ==. & row_dum2 !=. & distance_robust_border2 > -14.673 & distance_robust_border2 < 14.673, meanonly

replace ymean = sum_EUvoteshare_neg

eststo: estpost sum ymean if treat_AL ==. & row_dum2 !=. & distance_robust_border2 > -16.719    & distance_robust_border2 <  16.719    , meanonly

replace ymean = yes_share

eststo: estpost sum ymean if is_oldmoselle !=. & distance_old_meu_mos2 >  -10   & distance_old_meu_mos2 <  10   , meanonly

replace ymean = sum_EUvoteshare_neg

eststo: estpost sum ymean if is_oldmoselle !=. & distance_old_meu_mos2 > -10    & distance_old_meu_mos2 <  10   , meanonly

replace ymean = yes_share

eststo: estpost sum ymean if is_borderingAL !=. & distance_france2 >  -24.840   & distance_france2 <  24.840   , meanonly

replace ymean = sum_EUvoteshare_neg

eststo: estpost sum ymean if is_borderingAL !=. & distance_france2 > -26.194    & distance_france2 <  26.194   , meanonly
esttab using "..\Paper EU Identity\Tables\ID_Table_placebo_final_ymean.tex", cells("mean(fmt(2))") nomtitles collabels(none) fragment postfoot(\hline) nolines nogaps nonumbers booktabs noobs compress label replace varlabel(ymean "Mean of Outcome") 
estimates drop _all
drop ymean

*********************************************************************************************************************************
*************  Table D.15 RD results - Euroscepticism (1994, 1999 and 2004): Ray-Marks-Steenbergen Party Dataset  ***************
*********************************************************************************************************************************

estimates drop _all

use "processed data\reshaped_letter_AlsaceLorraine.dta", clear
estimates drop _all
drop if insee_code == 1

keep if year == 1994 | year == 1999 | year == 2004

gen cant_ID = ID_2*1000+ID_3


eststo: rdrobust sum_EU_VS_neg_ste distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) vce(cluster cant_ID)
estadd local Obs = e(N_h_r) + e(N_h_l)
local bdw_1 =  e(h_r)
eststo: rdrobust sum_EU_VS_neg_noFN_ste distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) vce(cluster cant_ID)
estadd local Obs = e(N_h_r) + e(N_h_l)
local bdw_2 =  e(h_r)
eststo: rdrobust sum_weight_EU_VS_neg2_ste distance2 if treat_AL !=., rho(1) kernel(uni) masspoints(off) covs($distances $segment2) vce(cluster cant_ID)
estadd local Obs = e(N_h_r) + e(N_h_l)  
local bdw_3 =  e(h_r) 
esttab using "..\Paper EU Identity\Tables\ID_Table_eurosceptic_final_steenbergen.tex", fragment booktabs nostar replace cells(b(star fmt(3) nostar) se(par(( )) abs fmt(3)) p(par({[ ]}) abs fmt(3)))  ///
				mlabel(none) style(fixed) collabels(none) nolines nogaps nonumbers varlabel(RD_Estimate "Treatment vs. Control") ///
				stats(h_r Obs, fmt(3 0) label("Bandwidth (km)" "Observations")) noabbr 

estimates drop _all

**control only 
gen ymean = sum_EU_VS_neg_ste

eststo: estpost sum ymean if treat_AL ==0 & distance2 > -`bdw_1'    & distance2 <  `bdw_1'  , meanonly

replace ymean = sum_EU_VS_neg_noFN_ste 

eststo: estpost sum ymean if treat_AL ==0 & distance2 > -`bdw_2'     & distance2 < `bdw_2'  , meanonly

replace ymean = sum_weight_EU_VS_neg2_ste

eststo: estpost sum ymean if treat_AL ==0 & distance2 > -`bdw_3'      & distance2 < `bdw_3' , meanonly

esttab using "..\Paper EU Identity\Tables\ID_Table_main_eurosceptic_final_ymean_control_steenbergen.tex", cells("mean(fmt(2))") nomtitles collabels(none) fragment postfoot(\hline) nolines nogaps nonumbers booktabs noobs compress label replace varlabel(ymean "Mean of Outcome (Control)") 
estimates drop _all
drop ymean


********************************************************************************
*************  Figure D.4 Eurosceptic Vote Share (1979-1989)  ******************
********************************************************************************

import excel "1979-1989_election_results.xlsx", firstrow clear
replace Euroscepticism_Index_Combined=0 if Euroscepticism_Index_Combined<0 & Euroscepticism_Index_Combined!=.
collapse (sum) Eurosceptic_Voteshare (sum) Euroscepticism_Index_Combined, by (Year Department)

gen treat_AL = .
replace treat_AL = 0 if Department == "Meurthe-et-Moselle" | Department == "Meuse" | Department == "Vosges"
replace treat_AL = 1 if Department == "Haut-Rhin" | Department == "Bas-Rhin" | Department == "Moselle"

estimates drop _all

collapse Eurosceptic_Voteshare Euroscepticism_Index_Combined, by(Year treat_AL)
replace Eurosceptic_Voteshare=100*Eurosceptic_Voteshare

separate Eurosceptic_Voteshare  , by( treat_AL == 1)


separate Euroscepticism_Index_Combined  , by( treat_AL == 1)


set scheme s2color	
label var Eurosceptic_Voteshare0 "Control" 
label var Eurosceptic_Voteshare1 "Treatment" 
graph  bar (mean) Eurosceptic_Voteshare0 Eurosceptic_Voteshare1, over( Year) bargap(20) /// 
ytitle("Eurosceptic Vote Share (in %)") graphregion(color(white)) bar(1,color("230 230 230")) bar(2,color("115 115 115")) nofill ///
legend(order(1 "Control" 2 "Treatment"))

graph export "..\Paper EU Identity\Graphs\bar_Eurosceptic_Voteshare_1979_1989.pdf", replace 
graph export "..\Paper EU Identity\Graphs\bar_Eurosceptic_Voteshare_1979_1989.png", replace width(3000) height(2000)


********************************************************************************
**************  Figure D.5 Euroscepticism Index (1979-1989)  *******************
********************************************************************************

graph  bar (mean) Euroscepticism_Index_Combined0 Euroscepticism_Index_Combined1, over( Year) bargap(20) /// 
ytitle("Euroscepticism Index") graphregion(color(white)) bar(1,color("230 230 230")) bar(2,color("115 115 115")) nofill ///
legend(order(1 "Control" 2 "Treatment"))

graph export "..\Paper EU Identity\Graphs\bar_Euroscepticism_Index_Combined_1979_1989.pdf", replace 
graph export "..\Paper EU Identity\Graphs\bar_Euroscepticism_Index_Combined_1979_1989.png", replace width(3000) height(2000)

save "processed data\1979-1989_election_results.dta", replace
set scheme plottig	


*********************************************************************************************************
***  Table D.16 Nested Identities - EU, National and Regional Level (all of France; extensive Table)  ***
*********************************************************************************************************

use "processed data\oip_attachment.dta", clear

eststo: reg st_attachement_region3 is_aslr age gender employmentstatus diplome, r
eststo: reg st_attachement_france3 is_aslr age gender employmentstatus diplome, r
eststo: reg st_attachement_europe3 is_aslr age gender employmentstatus diplome, r
esttab using "..\Paper EU Identity\Tables\ID_Table_opinions1_1_all.tex", fragment booktabs nostar replace cells(b(star fmt(3) nostar) se(par(( )) abs fmt(3)) p(par({[ ]}) abs fmt(3))) drop(_cons age gender employmentstatus diplome) ///
				mlabel(none) style(fixed) collabels(none) nolines nogaps nonumbers postfoot(\hline) varlabel(is_aslr "Treatment vs. Control")  /*prehead("")*/ ///
				stats( N, fmt( 0) label( "Observations")) noabbr 
estimates drop _all

use "processed data\oip_attachment.dta", clear

tab ID_2, gen(dep_dummy)

gen treated_all = 0 
replace treated_all = 1 if is_aslr == 1 

gen ID = st_attachement_france3
gen interaction = c.ID#treated_all 
eststo: reg st_attachement_region3 ID treated_all interaction age gender employmentstatus diplome dep_dummy1-dep_dummy85  , r
replace ID = st_attachement_europe3
replace interaction = c.ID#treated_all 
eststo: reg st_attachement_france3 ID treated_all interaction age gender employmentstatus diplome  dep_dummy1-dep_dummy85  , r
replace ID = st_attachement_region3
replace interaction = c.ID#treated_all 
eststo: reg st_attachement_europe3 ID treated_all interaction age gender employmentstatus diplome dep_dummy1-dep_dummy85  , r
esttab using "..\Paper EU Identity\Tables\ID_Table_complementarity6_2_all.tex", fragment booktabs nostar replace cells(b(star fmt(3) nostar) se(par(( )) abs fmt(3)) p(par({[ ]}) abs fmt(3))) drop(_cons age gender employmentstatus diplome dep_dummy*) order(treated_all ID interaction) ///
				mlabel(none) style(fixed) collabels(none) nolines nogaps nonumbers postfoot(\hline) varlabel(ID "Variable of Interest" treated_all "Treatment vs. Control" interaction "Interaction")  ///
				stats(N, fmt(0) label("Observations")) noabbr 
estimates drop _all
drop interaction
drop ID
drop treated_all


***************************************************************************************************************
***  Table D.17 Nested Identities - EU, National, and Regional Level (Alsace \& Lorraine; Extensive Table)  ***
***************************************************************************************************************

use "processed data\oip_attachment.dta", clear

tab ID_2, gen(dep_dummy)

gen treated_all = 0 
replace treated_all = 1 if is_aslr == 1 

gen ID = st_attachement_france
gen interaction = c.ID#treated_all 
eststo: reg st_attachement_region ID treated_all interaction age gender employmentstatus diplome dep_dummy1-dep_dummy85 if treat_AL !=. , r
replace ID = st_attachement_europe
replace interaction = c.ID#treated_all 
eststo: reg st_attachement_france ID treated_all interaction age gender employmentstatus diplome  dep_dummy1-dep_dummy85 if treat_AL !=. , r
replace ID = st_attachement_region
replace interaction = c.ID#treated_all 
eststo: reg st_attachement_europe ID treated_all interaction age gender employmentstatus diplome dep_dummy1-dep_dummy85 if treat_AL !=. , r
esttab using "..\Paper EU Identity\Tables\ID_Table_complementarity6_2_app.tex", fragment booktabs nostar replace cells(b(star fmt(3) nostar) se(par(( )) abs fmt(3)) p(par({[ ]}) abs fmt(3))) drop(_cons age gender employmentstatus diplome dep_dummy*) order(ID treated_all interaction) ///
				mlabel(none) style(fixed) collabels(none) nolines nogaps nonumbers postfoot(\hline) varlabel (ID "Variable of Interest" treated_all "Treatment vs. Control"  interaction "Interaction")  ///
				stats(N, fmt(0) label("Observations")) noabbr 
estimates drop _all
drop interaction
drop ID


********************************************************************************
******  Table D.18 EU as Preferred Level of Decision-Making - Age Groups *******
********************************************************************************

use "processed data\oip_dev_planning.dta", clear
estimates drop _all
eststo: reg st_EU_dev_plan is_aslr age gender employmentstatus diplome if treat_AL != . & age>=18 & age<=35, r
eststo: reg st_EU_dev_plan is_aslr age gender employmentstatus diplome if treat_AL != . & age>=36 & age<=55, r
eststo: reg st_EU_dev_plan is_aslr age gender employmentstatus diplome if treat_AL != . & age>=56 & age<=100, r
esttab using "..\Paper EU Identity\Tables\ID_Table_dev_plan1_age_groups.tex", fragment booktabs nostar replace cells(b(star fmt(3) nostar) se(par(( )) abs fmt(3)) p(par({[ ]}) abs fmt(3))) drop(_cons age gender employmentstatus diplome) ///
				mlabel(none) style(fixed) collabels(none) nolines nogaps nonumbers postfoot(\hline) varlabel(is_aslr "Treatment vs. Control")  /*prehead("")*/ ///
				stats( N, fmt( 0) label(  "Observations")) noabbr 
estimates drop _all


********************************************************************************
******  Table D.19 Survey evidence - Interactions Treatment with Demography ****
********************************************************************************

use "processed data\oip_attachment.dta", clear

tab ID_2, gen(dep_dummy)

gen treated_all = 0 
replace treated_all = 1 if is_aslr == 1 

gen experience = 0
replace experience = 1 if age >= 50 & year == 1995
replace experience = 1 if age >= 52 & year == 1997
replace experience = 1 if age >= 54 & year == 1999
replace experience = 1 if age >= 56 & year == 2001

gen high_ed2 = 0
replace high_ed2 = 1 if diplome > 2

estimates drop _all

gen interaction = c.age#is_aslr 
gen VOI = age
eststo: reg st_attachement_europe  is_aslr interaction  VOI gender employmentstatus diplome experience if treat_AL!=. , r
replace interaction = c.experience#is_aslr 
replace VOI = experience
eststo: reg st_attachement_europe  is_aslr interaction  VOI gender employmentstatus diplome if treat_AL!=. , r
replace interaction = c.gender#is_aslr 
replace VOI = gender
eststo: reg st_attachement_europe  is_aslr interaction age VOI employmentstatus diplome experience if treat_AL!=. , r
replace interaction = c.high_ed2#is_aslr
replace VOI = high_ed2 
eststo: reg st_attachement_europe  is_aslr interaction  age gender employmentstatus experience VOI if treat_AL!=. , r
esttab using "..\Paper EU Identity\Tables\ID_Table_demo_interactions2.tex", fragment booktabs nostar replace cells(b(star fmt(3) nostar) se(par(( )) abs fmt(3)) p(par({[ ]}) abs fmt(3))) drop(_cons age gender diplome experience employmentstatus ) order(is_aslr VOI interaction) ///
				mlabel(none) style(fixed) collabels(none) nolines nogaps nonumbers postfoot(\hline) varlabel(VOI "Variable of Interest" interaction "Treatment X V.o.I."  is_aslr "Treatment vs. Control")  ///
				stats(N, fmt(0) label("Observations")) noabbr 
estimates drop _all
cap drop interaction
cap drop VOI


********************************************************************************
**********  Table D.20 Share of Yes Votes and Religion, all of France. *********
********************************************************************************
use "processed data\natidentity2003_dep.dta", clear

eststo: reg r92_yf attend , r
eststo: reg r92_yf  D_attend1 D_attend2 D_attend3 D_attend4 D_attend5 , r
eststo: reg r92_yf  Relig2 Relig3 Relig4 Relig5 Relig6 Relig7 , r
***

eststo: reg r05_yf attend , r
eststo: reg r05_yf  D_attend1 D_attend2 D_attend3 D_attend4 D_attend5 , r
eststo: reg r05_yf  Relig2 Relig3 Relig4 Relig5 Relig6 Relig7 , r

*..\Paper EU Identity\
esttab using "..\Paper EU Identity\Tables\relig_yes.tex", fragment booktabs nostar replace cells(b(star fmt(3) nostar) se(par(( )) abs fmt(3)) p(par({[ ]}) abs fmt(3))) drop(_cons ) ///
				mlabel(none) style(fixed) collabels(none) nolines nogaps nonumbers label postfoot(\hline)   /*prehead("")*/ ///
				stats( N, fmt( 0) label(  "Observations")) noabbr 
estimates drop _all

********************************************************************************